MainFrm.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311
  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "icrEdit.h"
  5. #include "MainFrm.h"
  6. #include "IcrEditView.h"
  7. #include "resource.h"
  8. #include "..\include\kernel.h"
  9. #include "Const.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. DWORD CALLBACK EditStreamCallbackWriteToFile(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb);
  16. DWORD CALLBACK EditStreamCallbackOut(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb);
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CMainFrame
  19. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  20. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  21. //{{AFX_MSG_MAP(CMainFrame)
  22. ON_WM_CREATE()
  23. ON_CBN_SELCHANGE(IDC_COMBOX, OnSelchangeComboFind)
  24. ON_COMMAND(ID_EDITPASTE, OnEditPaste)
  25. ON_COMMAND(ID_EDITCUT, OnEditcut)
  26. ON_UPDATE_COMMAND_UI(ID_EDITCUT, OnUpdateEditcut)
  27. ON_COMMAND(ID_EDITCOPY, OnEditcopy)
  28. ON_UPDATE_COMMAND_UI(ID_EDITCOPY, OnUpdateEditcopy)
  29. ON_UPDATE_COMMAND_UI(ID_EDITPASTE, OnUpdateEditpaste)
  30. ON_COMMAND(ID_EDITUNDO, OnEditundo)
  31. ON_UPDATE_COMMAND_UI(ID_EDITUNDO, OnUpdateEditundo)
  32. ON_COMMAND(ID_EDITREDO, OnEditredo)
  33. ON_UPDATE_COMMAND_UI(ID_EDITREDO, OnUpdateEditredo)
  34. ON_COMMAND(ID_EDITSELECTALL, OnEditselectall)
  35. ON_COMMAND(ID_EDITREPEAT, OnEditrepeat)
  36. ON_COMMAND(ID_EDITREPEATNEXT, OnEditrepeatnext)
  37. ON_UPDATE_COMMAND_UI(ID_EDITREPEAT, OnUpdateEditrepeat)
  38. ON_UPDATE_COMMAND_UI(ID_EDITREPEATNEXT, OnUpdateEditrepeatnext)
  39. ON_COMMAND(ID_VIEW_FONT, OnViewFont)
  40. ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
  41. ON_COMMAND(ID_EDIT_TRIMTRAILLINGSPACE, OnEditTrimtraillingspace)
  42. ON_COMMAND(ID_EDIT_TRIMTRAILLINGTAB, OnEditTrimtraillingtab)
  43. ON_COMMAND(ID_EDIT_TABTOSPACE, OnEditTabtospace)
  44. ON_COMMAND(ID_EDIT_SPACETOTAB, OnEditSpacetotab)
  45. ON_COMMAND(ID_EDIT_LEADINGSPACETOTAB, OnEditLeadingspacetotab)
  46. ON_COMMAND(ID_EDIT_MOVERIGHT, OnEditMoveright)
  47. ON_COMMAND(ID_EDIT_UNCOMMENT, OnEditUncomment)
  48. ON_COMMAND(ID_EDIT_MOVELEFT, OnEditMoveleft)
  49. ON_COMMAND(ID_EDIT_COMMENT, OnEditComment)
  50. ON_COMMAND(ID_EDIT_LCASE, OnEditLcase)
  51. ON_COMMAND(ID_EDIT_UCASE, OnEditUcase)
  52. ON_COMMAND(ID_EDIT_INVERT, OnEditInvert)
  53. ON_COMMAND(ID_EDIT_CAPITALIZE, OnEditCapitalize)
  54. ON_COMMAND(ID_EDIT_SENTANCECASE, OnEditSentancecase)
  55. ON_UPDATE_COMMAND_UI(ID_EDIT_LCASE, OnUpdateEditLcase)
  56. ON_UPDATE_COMMAND_UI(ID_EDIT_INVERT, OnUpdateEditInvert)
  57. ON_UPDATE_COMMAND_UI(ID_EDIT_SENTANCECASE, OnUpdateEditSentancecase)
  58. ON_UPDATE_COMMAND_UI(ID_EDIT_UCASE, OnUpdateEditUcase)
  59. ON_COMMAND(ID_FILE_NEW, OnFileNew)
  60. ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
  61. ON_COMMAND(ID_FILESAVE, OnFilesave)
  62. ON_UPDATE_COMMAND_UI(ID_EDIT_CAPITALIZE, OnUpdateEditCapitalize)
  63. ON_WM_CLOSE()
  64. ON_COMMAND(ID_FILE_SAVE_AS_, OnFileSaveAs)
  65. //}}AFX_MSG_MAP
  66. ON_WM_GETMINMAXINFO()
  67. END_MESSAGE_MAP()
  68. static UINT indicators[] =
  69. {
  70. ID_SEPARATOR, // status line indicator
  71. ID_INDICATOR_CAPS,
  72. ID_INDICATOR_NUM,
  73. };
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CMainFrame construction/destruction
  76. CMainFrame::CMainFrame()
  77. {
  78. m_strFileName = "";
  79. }
  80. CMainFrame::~CMainFrame()
  81. {
  82. if( pVariantsManager )
  83. {
  84. delete pVariantsManager;
  85. pVariantsManager = NULL;
  86. }
  87. }
  88. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  89. {
  90. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  91. return -1;
  92. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  93. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  94. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  95. {
  96. TRACE0("Failed to create toolbar\n");
  97. return -1; // fail to create
  98. }
  99. // TODO: Delete these three lines if you don't want the toolbar to
  100. // be dockable
  101. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  102. EnableDocking(CBRS_ALIGN_ANY);
  103. DockControlBar(&m_wndToolBar);
  104. if (!m_wndStatusBar.Create(this) ||
  105. !m_wndStatusBar.SetIndicators(indicators,
  106. sizeof(indicators)/sizeof(UINT)))
  107. {
  108. TRACE0("Failed to create status bar\n");
  109. return -1; // fail to create
  110. }
  111. m_wndStatusBar.SetPaneInfo(1, ID_INDICATOR_CAPS, CBRS_BOTTOM,100);
  112. m_bAutoMenuEnable = FALSE;
  113. if(-1 == LoadToolbarCombo())
  114. return FALSE;
  115. CreateSystem();
  116. CHAR strDirectory[MAX_PATH_LENGTH + 1]; // 软件所在路径
  117. CHAR strAppName[MAX_PATH_LENGTH + 1] = {0}; // 软件名称
  118. CHAR strFile[MAX_FILE_LENGTH + 1] = "";
  119. CHAR strValue[MAX_VALUE_LENGTH + 1] = "";
  120. int iPosFile = 0;
  121. int iLenghtFile = 0;
  122. ////////////////////////////////////////////////////////////////////////////
  123. //获取应用名
  124. GetModuleFileName(AfxGetApp()->m_hInstance, strDirectory, MAX_PATH_LENGTH);
  125. iLenghtFile = strlen(strDirectory);
  126. for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
  127. {
  128. if (strDirectory[iPosFile] == '\\')
  129. {
  130. memset(strAppName, 0, sizeof(strAppName));
  131. memcpy(strAppName, strDirectory + iPosFile + 1, iLenghtFile - iPosFile - 1);
  132. break;
  133. }
  134. }
  135. //获取系统路径
  136. //#ifdef _DEBUG
  137. // GetCurrentDirectory(MAX_PATH_LENGTH, strDirectory);
  138. //#else
  139. GetModuleFileName(AfxGetApp()->m_hInstance, strDirectory, MAX_PATH_LENGTH);
  140. iLenghtFile = strlen(strDirectory);
  141. for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
  142. {
  143. if (strDirectory[iPosFile] == '\\')
  144. {
  145. strDirectory[iPosFile] = '\0';
  146. break;
  147. }
  148. }
  149. //#endif
  150. if( pVariantsManager != NULL )
  151. {
  152. pVariantsManager->Load(strDirectory);//pVariantsManager->GetVarInfo();//
  153. }
  154. return 0;
  155. }
  156. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  157. {
  158. if( !CFrameWnd::PreCreateWindow(cs) )
  159. return FALSE;
  160. // TODO: Modify the Window class or styles here by modifying
  161. // the CREATESTRUCT cs
  162. return TRUE;
  163. }
  164. /////////////////////////////////////////////////////////////////////////////
  165. // CMainFrame diagnostics
  166. #ifdef _DEBUG
  167. void CMainFrame::AssertValid() const
  168. {
  169. CFrameWnd::AssertValid();
  170. }
  171. void CMainFrame::Dump(CDumpContext& dc) const
  172. {
  173. CFrameWnd::Dump(dc);
  174. }
  175. #endif //_DEBUG
  176. /////////////////////////////////////////////////////////////////////////////
  177. // CMainFrame message handlers
  178. int CMainFrame::LoadToolbarCombo()
  179. {
  180. return 0;
  181. }
  182. void CMainFrame::OnEditPaste()
  183. {
  184. char * buffer;
  185. if(!OpenClipboard())
  186. return;
  187. buffer = (char*)::GetClipboardData(CF_TEXT);
  188. CloseClipboard();
  189. CString str = buffer;
  190. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  191. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  192. CWnd *pWnd = GetFocus();
  193. if(pWnd->m_hWnd!=edit.m_hWnd)
  194. {
  195. pWnd->SendMessage(WM_PASTE, 0, 0);
  196. return;
  197. }
  198. CHARRANGE cr;
  199. edit.GetSel(cr);
  200. icrEditView->SetParseCookieZeroFromGivenLine(edit.LineFromChar(cr.cpMin)); //粘贴时需重置解析缓冲区
  201. edit.ReplaceSel(str, TRUE);
  202. if(cr.cpMax != cr.cpMin)
  203. {
  204. icrEditView->ReCalcCursorPostion();
  205. }
  206. }
  207. void CMainFrame::OnEditcut()
  208. {
  209. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  210. CRichEditCtrl &SynCtrl = icrEditView->GetRichEditCtrl();
  211. CWnd *pWnd = GetFocus();
  212. if(pWnd->m_hWnd != SynCtrl.m_hWnd)
  213. {
  214. pWnd->SendMessage(WM_CUT, 0, 0);
  215. return;
  216. }
  217. CHARRANGE cr;
  218. SynCtrl.GetSel( cr );
  219. icrEditView->GetRichEditCtrl().Cut();
  220. if(cr.cpMax != cr.cpMin)
  221. {
  222. icrEditView->ReCalcCursorPostion();
  223. }
  224. else
  225. {
  226. SCROLLINFO si;
  227. si.cbSize = sizeof(si);
  228. icrEditView->GetScrollInfo(SB_HORZ, &si);
  229. icrEditView->m_nHorzMaxOld = si.nMax;
  230. }
  231. }
  232. void CMainFrame::OnUpdateEditcut(CCmdUI* pCmdUI)
  233. {
  234. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  235. CRichEditCtrl& editctrl = icrEditView->GetRichEditCtrl();
  236. CHARRANGE cr;
  237. editctrl.GetSel(cr);
  238. pCmdUI->Enable(cr.cpMin!=cr.cpMax);
  239. }
  240. void CMainFrame::OnEditcopy()
  241. {
  242. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  243. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  244. CWnd *pWnd = GetFocus();
  245. if(pWnd->m_hWnd != edit.m_hWnd)
  246. {
  247. pWnd->SendMessage(WM_COPY, 0, 0);
  248. }
  249. else
  250. {
  251. edit.Copy();
  252. }
  253. }
  254. void CMainFrame::OnUpdateEditcopy(CCmdUI* pCmdUI)
  255. {
  256. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  257. CRichEditCtrl& editctrl = icrEditView->GetRichEditCtrl();
  258. CHARRANGE cr;
  259. editctrl.GetSel(cr);
  260. pCmdUI->Enable(cr.cpMin!=cr.cpMax);
  261. }
  262. void CMainFrame::OnUpdateEditpaste(CCmdUI* pCmdUI)
  263. {
  264. OpenClipboard();
  265. if(::GetClipboardData(CF_TEXT)==FALSE)
  266. pCmdUI->Enable(FALSE);
  267. else
  268. pCmdUI->Enable(TRUE);
  269. CloseClipboard();
  270. }
  271. void CMainFrame::OnEditundo()
  272. {
  273. GetFocus()->SendMessage(EM_UNDO, 0, 0);
  274. }
  275. void CMainFrame::OnUpdateEditundo(CCmdUI* pCmdUI)
  276. {
  277. CWnd *pWnd = GetFocus();
  278. if(!pWnd)
  279. return;
  280. BOOL bCanUndo = pWnd->SendMessage(EM_CANUNDO, 0, 0);
  281. pCmdUI->Enable(bCanUndo);
  282. }
  283. void CMainFrame::OnEditredo()
  284. {
  285. GetFocus()->SendMessage(EM_REDO, 0, 0);
  286. }
  287. void CMainFrame::OnUpdateEditredo(CCmdUI* pCmdUI)
  288. {
  289. CWnd *pWnd = GetFocus();
  290. if(!pWnd)
  291. return;
  292. BOOL bCanRedo = pWnd->SendMessage(EM_CANREDO, 0, 0);
  293. pCmdUI->Enable(bCanRedo);
  294. }
  295. void CMainFrame::OnEditselectall()
  296. {
  297. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  298. CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
  299. CWnd *pWnd = GetFocus();
  300. if(pWnd->m_hWnd != editctrl.m_hWnd)
  301. {
  302. CString str;
  303. pWnd->GetWindowText(str);
  304. CHARRANGE ichCharRange;
  305. ichCharRange.cpMax = str.GetLength();
  306. ichCharRange.cpMin = 0;
  307. pWnd->SendMessage(EM_EXSETSEL, 0, (LPARAM)&ichCharRange);
  308. return;
  309. }
  310. editctrl.SetSel(0, -1);
  311. editctrl.SetFocus();
  312. editctrl.PostMessage( WM_PAINT, 0, 0 );
  313. }
  314. void CMainFrame::OnEditrepeat()
  315. {
  316. CWinApp *app = AfxGetApp();
  317. CMainFrame *mainfrm = (CMainFrame *)AfxGetMainWnd();
  318. CIcrEditView *icrEditView=(CIcrEditView *)GetActiveView();
  319. CString strEdit;
  320. BOOL bWholeWord = app->GetProfileInt(_T("CFind"), _T("WholeWord"), 0);
  321. BOOL bCase = app->GetProfileInt(_T("CFind"), _T("Case"), 0);
  322. if(strEdit.IsEmpty())
  323. return;
  324. int dwFlags = 0;
  325. if(bCase)
  326. dwFlags|=FR_MATCHCASE;
  327. if(bWholeWord)
  328. dwFlags|=FR_WHOLEWORD;
  329. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  330. CHARRANGE cr;
  331. edit.GetSel(cr);
  332. FINDTEXTEX *ft = new FINDTEXTEX[1];
  333. ft->chrg.cpMin = cr.cpMin-1;
  334. ft->chrg.cpMax = -1;// search through end of the text
  335. TCHAR *t = new TCHAR[strEdit.GetLength()+1];
  336. strcpy(t, strEdit);
  337. ft->lpstrText = t;
  338. icrEditView->ShowWindow(SW_HIDE);
  339. int nPos = edit.SendMessage(EM_FINDTEXTEX, dwFlags, (LPARAM)ft);
  340. if(nPos!=-1) {
  341. edit.SetSel(ft->chrgText.cpMin, ft->chrgText.cpMax);
  342. icrEditView->SetFocus();
  343. SetFocus();
  344. icrEditView->ShowWindow(SW_SHOW);
  345. }
  346. else {
  347. icrEditView->ShowWindow(SW_SHOW);
  348. CString strShow;
  349. strShow.Format(_T("Cannot find the string: \"%s\", search again from the end?"), strEdit);
  350. if(MessageBox(strShow,_T("Find"), MB_ICONINFORMATION|MB_YESNO)==IDYES)
  351. {
  352. icrEditView->ShowWindow(SW_HIDE);
  353. edit.SetSel(0, -1);
  354. icrEditView->ShowWindow(SW_SHOW);
  355. CHARRANGE cr;
  356. edit.GetSel(cr);
  357. edit.SetSel(cr.cpMax, cr.cpMax);
  358. OnEditrepeat();
  359. if(t)
  360. delete t;
  361. if(ft)
  362. delete ft;
  363. return;
  364. }
  365. }
  366. if(t)
  367. delete t;
  368. if(ft)
  369. delete ft;
  370. }
  371. void CMainFrame::OnEditrepeatnext()
  372. {
  373. CWinApp *app = AfxGetApp();
  374. CMainFrame *mainfrm = (CMainFrame *)AfxGetMainWnd();
  375. CIcrEditView *icrEditView=(CIcrEditView *)GetActiveView();
  376. CString strEdit;
  377. BOOL bWholeWord = app->GetProfileInt(_T("CFind"), _T("WholeWord"), 0);
  378. BOOL bCase = app->GetProfileInt(_T("CFind"), _T("Case"), 0);
  379. if(strEdit.IsEmpty())
  380. return;
  381. int dwFlags = 0;
  382. if(bCase)
  383. dwFlags|=FR_MATCHCASE;
  384. if(bWholeWord)
  385. dwFlags|=FR_WHOLEWORD;
  386. dwFlags|=FR_DOWN;;
  387. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  388. CHARRANGE cr;
  389. edit.GetSel(cr);
  390. FINDTEXTEX *ft = new FINDTEXTEX[1];
  391. ft->chrg.cpMin = cr.cpMin+1;
  392. ft->chrg.cpMax = -1;// search through end of the text
  393. TCHAR *t = new TCHAR[strEdit.GetLength()+1];
  394. strcpy(t, strEdit);
  395. ft->lpstrText = t;
  396. icrEditView->ShowWindow(SW_HIDE);
  397. int nPos = edit.SendMessage(EM_FINDTEXTEX, dwFlags, (LPARAM)ft);
  398. if(nPos!=-1) {
  399. edit.SetSel(ft->chrgText.cpMin, ft->chrgText.cpMax);
  400. icrEditView->SetFocus();
  401. SetFocus();
  402. icrEditView->ShowWindow(SW_SHOW);
  403. }
  404. else {
  405. icrEditView->ShowWindow(SW_SHOW);
  406. CString strShow;
  407. strShow.Format(_T("Cannot find the string: \"%s\", search again from the beginning?"), strEdit);
  408. if(MessageBox(strShow, _T("Find"), MB_ICONINFORMATION|MB_YESNO)==IDYES)
  409. {
  410. edit.SetSel(0, 0);
  411. OnEditrepeatnext();
  412. if(t)
  413. delete t;
  414. if(ft)
  415. delete ft;
  416. return;
  417. }
  418. }
  419. if(t)
  420. delete t;
  421. if(ft)
  422. delete ft;
  423. }
  424. void CMainFrame::OnUpdateEditrepeat(CCmdUI* pCmdUI)
  425. {
  426. }
  427. void CMainFrame::OnUpdateEditrepeatnext(CCmdUI* pCmdUI)
  428. {
  429. }
  430. void CMainFrame::OnViewFont()
  431. {
  432. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  433. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  434. BOOL bModify = edit.GetModify();
  435. edit.ShowWindow(SW_HIDE);
  436. CString strText;
  437. EDITSTREAM stream;
  438. stream.dwCookie = (DWORD)&strText;
  439. stream.pfnCallback = EditStreamCallbackOut;
  440. edit.StreamOut(SF_TEXT, stream);
  441. CHARFORMAT cr;
  442. if(strText.IsEmpty())
  443. {
  444. strText = _T(" ");
  445. edit.SetSel(0, 1);
  446. cr = icrEditView->GetCharFormatSelection();
  447. edit.SetSel(0, 0);
  448. }
  449. else
  450. {
  451. CHARRANGE range;
  452. edit.GetSel(range);
  453. int ntemp;
  454. if(range.cpMax < range.cpMin)
  455. {
  456. ntemp = range.cpMax;
  457. range.cpMax = range.cpMin;
  458. range.cpMin = ntemp;
  459. }
  460. if(range.cpMax == range.cpMin)
  461. {
  462. if(range.cpMin == 0)
  463. {
  464. edit.SetSel(0, 1);
  465. }
  466. else
  467. {
  468. edit.SetSel(range.cpMin-1, range.cpMin);
  469. }
  470. cr = icrEditView->GetCharFormatSelection();
  471. edit.SetSel(range.cpMin, range.cpMin);
  472. }
  473. else
  474. {
  475. cr = icrEditView->GetCharFormatSelection();
  476. }
  477. }
  478. edit.ShowWindow(SW_SHOW);
  479. CFontDialog dlg(cr, CF_BOTH|CF_NOOEMFONTS);
  480. if (dlg.DoModal() == IDOK)
  481. {
  482. CHARFORMAT cr;
  483. dlg.GetCharFormat(cr);
  484. LockWindowUpdate();
  485. icrEditView->SetWindowText(_T(""));
  486. icrEditView->SetSynEditViewFont(*dlg.m_cf.lpLogFont);
  487. icrEditView->SetWindowText(strText);
  488. edit.SetModify(bModify);
  489. UnlockWindowUpdate();
  490. }
  491. }
  492. void CMainFrame::SaveTheContext()
  493. {
  494. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  495. CRichEditCtrl &richctrl=icrEditView->GetRichEditCtrl();
  496. if(0 == m_strFileName.GetLength())
  497. return;
  498. CFile cFile(m_strFileName, CFile::modeCreate|CFile::modeWrite);
  499. EDITSTREAM es;
  500. es.dwCookie = (DWORD) &cFile;
  501. es.pfnCallback = EditStreamCallbackWriteToFile;
  502. richctrl.StreamOut(SF_TEXT, es);
  503. richctrl.SetModify(FALSE);
  504. }
  505. void CMainFrame::OnFileOpen()
  506. {
  507. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  508. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  509. if(edit.GetModify())
  510. {
  511. if(MessageBox("文件已经修改,需要保存吗??", "", MB_YESNO|MB_ICONQUESTION)==IDNO)
  512. ;
  513. else //保存
  514. {
  515. OnFilesave();
  516. }
  517. }
  518. CFileDialog fd (TRUE, _T(""), NULL, OFN_HIDEREADONLY|OFN_EXPLORER, "*.srp|*.srp||");
  519. if(IDCANCEL == fd.DoModal())
  520. {
  521. return;
  522. }
  523. m_strFileName = fd.GetPathName();
  524. icrEditView->LoadFile(m_strFileName);
  525. }
  526. void CMainFrame::OnEditTrimtraillingspace()
  527. {
  528. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  529. CWaitCursor wc;
  530. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  531. int nfirstline = edit.GetFirstVisibleLine();
  532. CHARRANGE cr;
  533. edit.GetSel(cr);
  534. int nline = edit.LineFromChar(cr.cpMin);
  535. CString strtext;
  536. EDITSTREAM stream;
  537. stream.dwCookie = (DWORD)&strtext;
  538. stream.pfnCallback = EditStreamCallbackOut;
  539. edit.StreamOut(SF_TEXT, stream);
  540. CString strnewtext = _T(""), strline;
  541. int npos = strtext.Find('\n');
  542. while(npos!=-1) {
  543. strline = strtext.Left(npos-1);
  544. strline.TrimRight(0x20);
  545. strline += '\n';
  546. strtext = strtext.Right(strtext.GetLength()-npos-1);
  547. strnewtext += strline;
  548. npos = strtext.Find('\n');
  549. }
  550. icrEditView->LoadText(strnewtext);
  551. icrEditView->GotoLine(nfirstline+1);
  552. int nlineindex = edit.LineIndex(nline);
  553. edit.SetSel(nlineindex, nlineindex);
  554. icrEditView->ShowCursorPosition();
  555. icrEditView->SetFocus();
  556. SaveTheContext();
  557. }
  558. void CMainFrame::OnEditTrimtraillingtab()
  559. {
  560. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  561. CWaitCursor wc;
  562. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  563. int nfirstline = edit.GetFirstVisibleLine();
  564. CHARRANGE cr;
  565. edit.GetSel(cr);
  566. int nline = edit.LineFromChar(cr.cpMin);
  567. CString strtext;
  568. EDITSTREAM stream;
  569. stream.dwCookie = (DWORD)&strtext;
  570. stream.pfnCallback = EditStreamCallbackOut;
  571. edit.StreamOut(SF_TEXT, stream);
  572. CString strnewtext = _T(""), strline;
  573. int npos = strtext.Find('\n');
  574. while(npos!=-1) {
  575. strline = strtext.Left(npos-1);
  576. strline.TrimRight(0x9);
  577. strline += '\n';
  578. strtext = strtext.Right(strtext.GetLength()-npos-1);
  579. strnewtext += strline;
  580. npos = strtext.Find('\n');
  581. }
  582. icrEditView->LoadText(strnewtext);
  583. icrEditView->GotoLine(nfirstline+1);
  584. int nlineindex = edit.LineIndex(nline);
  585. edit.SetSel(nlineindex, nlineindex);
  586. icrEditView->ShowCursorPosition();
  587. icrEditView->SetFocus();
  588. SaveTheContext();
  589. }
  590. void CMainFrame::OnEditTabtospace()
  591. {
  592. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  593. CWaitCursor wc;
  594. TCHAR chr = 0x9;
  595. CString strtab = chr;
  596. int ntabsize = icrEditView->GetTabSize();
  597. CString strspace((char)0x20, ntabsize);
  598. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  599. int nfirstline = edit.GetFirstVisibleLine();
  600. CHARRANGE cr;
  601. edit.GetSel(cr);
  602. int nline = edit.LineFromChar(cr.cpMin);
  603. CString strtext;
  604. EDITSTREAM stream;
  605. stream.dwCookie = (DWORD)&strtext;
  606. stream.pfnCallback = EditStreamCallbackOut;
  607. edit.StreamOut(SF_TEXT, stream);
  608. strtext.Replace(strtab, strspace);
  609. icrEditView->LoadText(strtext);
  610. icrEditView->GotoLine(nfirstline+1);
  611. int nlineindex = edit.LineIndex(nline);
  612. edit.SetSel(nlineindex, nlineindex);
  613. icrEditView->ShowCursorPosition();
  614. icrEditView->SetFocus();
  615. SaveTheContext();
  616. }
  617. void CMainFrame::OnEditSpacetotab()
  618. {
  619. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  620. CWaitCursor wc;
  621. TCHAR chr = 0x9;
  622. CString strtab = chr;
  623. int ntabsize = icrEditView->GetTabSize();
  624. CString strspace((char)0x20, ntabsize);
  625. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  626. int nfirstline = edit.GetFirstVisibleLine();
  627. CHARRANGE cr;
  628. edit.GetSel(cr);
  629. int nline = edit.LineFromChar(cr.cpMin);
  630. CString strtext;
  631. EDITSTREAM stream;
  632. stream.dwCookie = (DWORD)&strtext;
  633. stream.pfnCallback = EditStreamCallbackOut;
  634. edit.StreamOut(SF_TEXT, stream);
  635. strtext.Replace(strspace, strtab);
  636. icrEditView->LoadText(strtext);
  637. icrEditView->GotoLine(nfirstline+1);
  638. int nlineindex = edit.LineIndex(nline);
  639. edit.SetSel(nlineindex, nlineindex);
  640. icrEditView->ShowCursorPosition();
  641. icrEditView->SetFocus();
  642. SaveTheContext();
  643. }
  644. void CMainFrame::OnEditLeadingspacetotab()
  645. {
  646. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  647. CWaitCursor wc;
  648. int ntabsize = icrEditView->GetTabSize();
  649. CString strspace((char)0x20, ntabsize);
  650. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  651. int nfirstline = edit.GetFirstVisibleLine();
  652. CHARRANGE cr;
  653. edit.GetSel(cr);
  654. int nline = edit.LineFromChar(cr.cpMin);
  655. CString strtext;
  656. EDITSTREAM stream;
  657. stream.dwCookie = (DWORD)&strtext;
  658. stream.pfnCallback = EditStreamCallbackOut;
  659. edit.StreamOut(SF_TEXT, stream);
  660. CString strnewtext = _T(""), strline;
  661. int npos = strtext.Find('\n');
  662. while(npos!=-1) {
  663. int i=0;
  664. strline = strtext.Left(npos);
  665. while(strline[i]==0x20 || strline[i]==0x9)
  666. i++;
  667. CString strtmp = strline.Left(i);
  668. strtmp.Replace( strspace, _T("\t"));
  669. strline = strtmp + strline.Right(strline.GetLength()-i);
  670. strline += '\n';
  671. strtext = strtext.Right(strtext.GetLength()-npos-1);
  672. strnewtext += strline;
  673. npos = strtext.Find('\n');
  674. }
  675. icrEditView->LoadText(strnewtext);
  676. icrEditView->GotoLine(nfirstline+1);
  677. int nlineindex = edit.LineIndex(nline);
  678. edit.SetSel(nlineindex, nlineindex);
  679. icrEditView->ShowCursorPosition();
  680. icrEditView->SetFocus();
  681. SaveTheContext();
  682. }
  683. void CMainFrame::OnEditMoveright()
  684. {
  685. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  686. CRichEditCtrl &SynCtrl = icrEditView->GetRichEditCtrl();
  687. icrEditView->ShowWindow(SW_HIDE);
  688. int nfirstline, nendline;
  689. icrEditView->GetSelLine(nfirstline, nendline);
  690. CString strtext=_T(""), strline;
  691. BOOL bpriorlinerealreturn;
  692. int linenumber = nendline - nfirstline + 1;
  693. for(int i=0; i<linenumber; i++) {
  694. if(nfirstline+i-1<0)//判断前一行行末是否是硬回车
  695. bpriorlinerealreturn = TRUE;
  696. else
  697. bpriorlinerealreturn = icrEditView->GetLineString(nfirstline+i-1, strline);
  698. icrEditView->GetLineString(nfirstline+i, strline);
  699. if(bpriorlinerealreturn || nfirstline==nendline) { //如果上一行是真的换行
  700. int nselstart = SynCtrl.LineIndex(nfirstline+i);
  701. SynCtrl.SetSel(nselstart, nselstart);
  702. int noldlinecount = SynCtrl.GetLineCount();
  703. SynCtrl.ReplaceSel(_T("\t"), TRUE); //替换后可能引总行数增加
  704. int nnewlinecount = SynCtrl.GetLineCount();
  705. linenumber+=nnewlinecount-noldlinecount;
  706. }
  707. }
  708. int nselstart = SynCtrl.LineIndex(nfirstline);
  709. int nselend = SynCtrl.LineIndex(nfirstline+linenumber);
  710. SynCtrl.SetSel(nselstart, nselend);
  711. icrEditView->ShowWindow(SW_SHOW);
  712. }
  713. void CMainFrame::OnEditMoveleft()
  714. {
  715. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  716. CRichEditCtrl &SynCtrl = icrEditView->GetRichEditCtrl();
  717. icrEditView->ShowWindow(SW_HIDE);
  718. int nfirstline, nendline;
  719. icrEditView->GetSelLine(nfirstline, nendline);
  720. CString strtext=_T(""), strline;
  721. BOOL bpriorlinerealreturn;
  722. int linenumber = nendline - nfirstline + 1;
  723. for(int i=0; i<linenumber; i++) {
  724. if(nfirstline+i-1<0)//判断前一行行末是否是硬回车
  725. bpriorlinerealreturn = TRUE;
  726. else
  727. bpriorlinerealreturn = icrEditView->GetLineString(nfirstline+i-1, strline);
  728. icrEditView->GetLineString(nfirstline+i, strline);
  729. if(bpriorlinerealreturn || nfirstline==nendline) { //如果上一行是真的换行
  730. int nselstart = SynCtrl.LineIndex(nfirstline+i);
  731. SynCtrl.SetSel(nselstart, nselstart);
  732. if(strline.Left(1)==_T("\t")) {
  733. SynCtrl.SetSel(nselstart, nselstart+1);
  734. SynCtrl.ReplaceSel(_T(""), TRUE); //替换后可能引总行数减少
  735. }
  736. else {
  737. if(strline!=_T(" ")) { //之所以有此判断是因为如果是空行icrEditView->GetLineString会返回一个空格
  738. int ncount = (strline.GetLength()>icrEditView->GetTabSize()? strline.GetLength():icrEditView->GetTabSize());
  739. for(int j=0; j<ncount; j++) {
  740. if(strline[j]!=0x20)
  741. break;
  742. }
  743. SynCtrl.SetSel(nselstart, nselstart+j);
  744. SynCtrl.ReplaceSel(_T(""), TRUE); //替换后可能引总行数减少
  745. }
  746. }
  747. int noldlinecount = SynCtrl.GetLineCount();
  748. int nnewlinecount = SynCtrl.GetLineCount();
  749. linenumber+=nnewlinecount-noldlinecount;
  750. }
  751. }
  752. int nselstart = SynCtrl.LineIndex(nfirstline);
  753. int nselend = SynCtrl.LineIndex(nfirstline+linenumber);
  754. SynCtrl.SetSel(nselstart, nselend);
  755. icrEditView->ShowWindow(SW_SHOW);
  756. }
  757. void CMainFrame::OnEditUncomment()
  758. {
  759. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  760. CRichEditCtrl &SynCtrl = icrEditView->GetRichEditCtrl();
  761. int nfirstline, nendline;
  762. icrEditView->GetSelLine(nfirstline, nendline);
  763. //取当前语言对应的单行注释字符串
  764. CString strsinglecomment=icrEditView->GetSingleCommentString(icrEditView->GetLanguage());
  765. if(strsinglecomment.IsEmpty()) //若为空串表示当前没有进行语法关键字显示
  766. return;
  767. CString strtext=_T(""), strline;
  768. icrEditView->ShowWindow(SW_HIDE);
  769. BOOL bpriorlinerealreturn;
  770. int linenumber = nendline - nfirstline + 1;
  771. for(int i=0; i<linenumber; i++) {
  772. if(nfirstline+i-1<0)//判断前一行行末是否是硬回车
  773. bpriorlinerealreturn = TRUE;
  774. else
  775. bpriorlinerealreturn = icrEditView->GetLineString(nfirstline+i-1, strline);
  776. icrEditView->GetLineString(nfirstline+i, strline);
  777. if(bpriorlinerealreturn || nfirstline==nendline) { //如果上一行是真的换行
  778. int nselstart = SynCtrl.LineIndex(nfirstline+i);
  779. SynCtrl.SetSel(nselstart, nselstart);
  780. if(strline!=_T(" ")) {
  781. if(strline.Left(strsinglecomment.GetLength())==strsinglecomment)
  782. SynCtrl.SetSel(nselstart, nselstart+strsinglecomment.GetLength());
  783. else {
  784. CString strtmp = strline;
  785. if(strtmp.GetLength()!=0) {
  786. while(strtmp.GetAt(0)==0x20 || strtmp.GetAt(0)=='\t') {
  787. strtmp.TrimLeft(0x20);
  788. strtmp.TrimLeft('\t');
  789. if(strtmp.GetLength()==0)
  790. break;
  791. }
  792. if(strtmp.GetLength()>=strsinglecomment.GetLength() ) {
  793. if(strtmp.Left(strsinglecomment.GetLength())==strsinglecomment) {
  794. int npos = strline.Find(strsinglecomment);
  795. SynCtrl.SetSel( nselstart+npos, nselstart+npos+strsinglecomment.GetLength());
  796. }
  797. }
  798. }
  799. }
  800. }
  801. int noldlinecount=SynCtrl.GetLineCount();
  802. SynCtrl.ReplaceSel(_T(""), TRUE); //此行可能引起总的行数减少
  803. int nnewlinecount=SynCtrl.GetLineCount();
  804. linenumber+=nnewlinecount-noldlinecount;
  805. }
  806. }
  807. int nselstart = SynCtrl.LineIndex(nfirstline);
  808. int nselend = SynCtrl.LineIndex(nfirstline+linenumber);
  809. SynCtrl.SetSel(nselstart, nselend);
  810. icrEditView->ShowWindow(SW_SHOW);
  811. }
  812. void CMainFrame::OnEditComment()
  813. {
  814. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  815. CRichEditCtrl &SynCtrl = icrEditView->GetRichEditCtrl();
  816. int nfirstline, nendline;
  817. icrEditView->GetSelLine(nfirstline, nendline);
  818. //取当前语言对应的单行注释字符串
  819. CString strsinglecomment=icrEditView->GetSingleCommentString(icrEditView->GetLanguage());
  820. if(strsinglecomment.IsEmpty()) //若为空串表示当前没有进行语法关键字显示
  821. return;
  822. icrEditView->ShowWindow(SW_HIDE);
  823. CString strtext=_T(""), strline;
  824. BOOL bpriorlinerealreturn;
  825. int linenumber = nendline - nfirstline + 1;
  826. for(int i=0; i<linenumber; i++) {
  827. if(nfirstline+i-1<0)//判断前一行行末是否是硬回车
  828. bpriorlinerealreturn = TRUE;
  829. else
  830. bpriorlinerealreturn = icrEditView->GetLineString(nfirstline+i-1, strline);
  831. icrEditView->GetLineString(nfirstline+i, strline);
  832. if(bpriorlinerealreturn || nfirstline==nendline) { //如果上一行是真的换行
  833. int nselstart = SynCtrl.LineIndex(nfirstline+i);
  834. SynCtrl.SetSel(nselstart, nselstart);
  835. int noldlinecount = SynCtrl.GetLineCount();
  836. SynCtrl.ReplaceSel(strsinglecomment, TRUE);
  837. int nnewlinecount = SynCtrl.GetLineCount();
  838. linenumber+=nnewlinecount-noldlinecount;
  839. }
  840. }
  841. int nselstart = SynCtrl.LineIndex(nfirstline);
  842. int nselend = SynCtrl.LineIndex(nfirstline+linenumber);
  843. SynCtrl.SetSel(nselstart, nselend);
  844. icrEditView->ShowWindow(SW_SHOW);
  845. }
  846. void CMainFrame::OnEditLcase()
  847. {
  848. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  849. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  850. CHARRANGE cr;
  851. edit.GetSel(cr);
  852. CString strsel;
  853. EDITSTREAM stream;
  854. stream.dwCookie = (DWORD)&strsel;
  855. stream.pfnCallback = EditStreamCallbackOut;
  856. edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
  857. strsel.MakeLower();
  858. edit.ReplaceSel(strsel, TRUE);
  859. edit.SetSel(cr);
  860. }
  861. void CMainFrame::OnEditUcase()
  862. {
  863. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  864. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  865. CHARRANGE cr;
  866. edit.GetSel(cr);
  867. CString strsel;
  868. EDITSTREAM stream;
  869. stream.dwCookie = (DWORD)&strsel;
  870. stream.pfnCallback = EditStreamCallbackOut;
  871. edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
  872. strsel.MakeUpper();
  873. edit.ReplaceSel(strsel, TRUE);
  874. edit.SetSel(cr);
  875. }
  876. void CMainFrame::OnEditInvert()
  877. {
  878. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  879. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  880. CHARRANGE cr;
  881. edit.GetSel(cr);
  882. CString strsel;
  883. EDITSTREAM stream;
  884. stream.dwCookie = (DWORD)&strsel;
  885. stream.pfnCallback = EditStreamCallbackOut;
  886. edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
  887. for(int i=0; i<strsel.GetLength(); i++) {
  888. TCHAR ch = strsel[i];
  889. if( ch >='A' && ch <='Z' )
  890. strsel.SetAt(i, ch + 'a' - 'A');
  891. else if( ch >='a' && ch <='z' )
  892. strsel.SetAt(i, ch + 'A' - 'a');
  893. }
  894. edit.ReplaceSel(strsel, TRUE);
  895. edit.SetSel(cr);
  896. }
  897. void CMainFrame::OnEditCapitalize()
  898. {
  899. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  900. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  901. CHARRANGE cr;
  902. edit.GetSel(cr);
  903. CString strsel;
  904. EDITSTREAM stream;
  905. stream.dwCookie = (DWORD)&strsel;
  906. stream.pfnCallback = EditStreamCallbackOut;
  907. edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
  908. strsel.MakeLower();
  909. BOOL bIsChar = FALSE, bInString=FALSE;
  910. for(int i=0; i<strsel.GetLength(); i++) {
  911. TCHAR ch = strsel[i];
  912. if( ch >='a' && ch <='z' && !bIsChar) {
  913. strsel.SetAt(i, ch + 'A' - 'a');
  914. }
  915. if( (ch >='a' && ch <='z') || (ch >='A' && ch <='Z') )
  916. bIsChar = TRUE;
  917. else
  918. bIsChar = FALSE;
  919. }
  920. edit.ReplaceSel(strsel, TRUE);
  921. edit.SetSel(cr);
  922. }
  923. void CMainFrame::OnEditSentancecase()
  924. {
  925. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  926. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  927. CHARRANGE cr;
  928. edit.GetSel(cr);
  929. CString strsel;
  930. EDITSTREAM stream;
  931. stream.dwCookie = (DWORD)&strsel;
  932. stream.pfnCallback = EditStreamCallbackOut;
  933. edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
  934. BOOL bDo = TRUE;
  935. for(int i=0; i<strsel.GetLength(); i++) {
  936. TCHAR ch = strsel[i];
  937. if(ch == 0xa)
  938. bDo = TRUE;
  939. if( ((ch >='a' && ch <='z') || (ch >='A' && ch <='Z')) && bDo) {
  940. if( ch >='A' && ch <='Z' )
  941. strsel.SetAt(i, ch + 'a' - 'A');
  942. else
  943. strsel.SetAt(i, ch + 'A' - 'a');
  944. bDo = FALSE;
  945. }
  946. }
  947. edit.ReplaceSel(strsel, TRUE);
  948. edit.SetSel(cr);
  949. }
  950. CString CMainFrame::GetFileContext(CString strfile)
  951. {
  952. CString str=_T("");;
  953. CFileException fe;
  954. CFile file;
  955. file.Open(strfile, CFile::modeRead, &fe);
  956. if(fe.m_cause != CFileException::none) {
  957. fe.ReportError();
  958. return _T("");
  959. }
  960. DWORD dwSize=(DWORD)file.GetLength();
  961. if(dwSize==0)
  962. return _T("");
  963. try {
  964. LPSTR lpszContext=new TCHAR[1];
  965. file.Read(lpszContext, 1);
  966. if(*lpszContext==-1) {
  967. if(lpszContext!=NULL)
  968. delete lpszContext;
  969. LPWSTR lpsztext= new WCHAR[1];
  970. file.Read(lpsztext, 1);
  971. if(lpsztext!=NULL)
  972. delete lpsztext;
  973. lpsztext= new WCHAR[dwSize-1];
  974. DWORD dwRead=file.Read(lpsztext, dwSize-2);
  975. lpsztext[dwRead/2]=0;
  976. str=lpsztext;
  977. if(lpsztext!=NULL)
  978. delete lpsztext;
  979. }
  980. else {
  981. if(lpszContext!=NULL)
  982. delete lpszContext;
  983. lpszContext=new TCHAR[dwSize+2];
  984. file.Seek(0, CFile::begin);
  985. DWORD dwRead=file.Read(lpszContext, dwSize);
  986. file.Close();
  987. lpszContext[dwRead]='\0';
  988. str=lpszContext;
  989. if(lpszContext!=NULL)
  990. delete lpszContext;
  991. }
  992. }
  993. catch(...){}
  994. return str;
  995. }
  996. void CMainFrame::OnSelchangeComboFind()
  997. {
  998. }
  999. void CMainFrame::OnUpdateEditLcase(CCmdUI* pCmdUI)
  1000. {
  1001. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  1002. CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
  1003. CHARRANGE cr;
  1004. editctrl.GetSel(cr);
  1005. pCmdUI->Enable(cr.cpMin!=cr.cpMax);
  1006. }
  1007. void CMainFrame::OnUpdateEditInvert(CCmdUI* pCmdUI)
  1008. {
  1009. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  1010. CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
  1011. CHARRANGE cr;
  1012. editctrl.GetSel(cr);
  1013. pCmdUI->Enable(cr.cpMin!=cr.cpMax);
  1014. }
  1015. void CMainFrame::OnUpdateEditSentancecase(CCmdUI* pCmdUI)
  1016. {
  1017. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  1018. CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
  1019. CHARRANGE cr;
  1020. editctrl.GetSel(cr);
  1021. pCmdUI->Enable(cr.cpMin!=cr.cpMax);
  1022. }
  1023. void CMainFrame::OnUpdateEditUcase(CCmdUI* pCmdUI)
  1024. {
  1025. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  1026. CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
  1027. CHARRANGE cr;
  1028. editctrl.GetSel(cr);
  1029. pCmdUI->Enable(cr.cpMin!=cr.cpMax);
  1030. }
  1031. void CMainFrame::OnFileNew()
  1032. {
  1033. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  1034. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  1035. if(!m_strFileName.IsEmpty())
  1036. {
  1037. if(edit.GetModify())
  1038. {
  1039. if(MessageBox("文件已经修改,需要保存吗?", "", MB_YESNO|MB_ICONQUESTION)==IDYES)
  1040. {
  1041. SaveTheContext();
  1042. }
  1043. }
  1044. }
  1045. edit.SetWindowText("");
  1046. m_strFileName = "";
  1047. icrEditView->SetSynEditViewFont(icrEditView->GetSynEditViewFont());
  1048. }
  1049. void CMainFrame::OnFileSaveAs()
  1050. {
  1051. if(m_strFileName.IsEmpty())
  1052. {
  1053. CFileDialog fd ( FALSE, _T(""), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("*.srp|*.srp||"));
  1054. if(fd.DoModal()==IDCANCEL)
  1055. return;
  1056. m_strFileName = fd.GetPathName();
  1057. }
  1058. else
  1059. {
  1060. CString strFileName = m_strFileName;
  1061. int nPos= strFileName.ReverseFind('\\');
  1062. strFileName = strFileName.Right(strFileName.GetLength()-nPos-1);
  1063. CFileDialog fd ( FALSE, "", NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("*.srp|*.srp||"));
  1064. wsprintf(fd.m_ofn.lpstrFile, strFileName);
  1065. if(fd.DoModal()==IDCANCEL)
  1066. return;
  1067. m_strFileName = fd.GetPathName();
  1068. }
  1069. SaveTheContext();
  1070. }
  1071. void CMainFrame::OnFilesave()
  1072. {
  1073. if(m_strFileName.IsEmpty())
  1074. {
  1075. CFileDialog fd ( FALSE, _T(""), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("*.srp|*.srp||"));
  1076. if(fd.DoModal()==IDCANCEL)
  1077. return;
  1078. m_strFileName = fd.GetPathName();
  1079. }
  1080. SaveTheContext();
  1081. }
  1082. void CMainFrame::OnUpdateEditCapitalize(CCmdUI* pCmdUI)
  1083. {
  1084. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  1085. CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
  1086. CHARRANGE cr;
  1087. editctrl.GetSel(cr);
  1088. pCmdUI->Enable(cr.cpMin!=cr.cpMax);
  1089. }
  1090. void CMainFrame::OnClose()
  1091. {
  1092. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  1093. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  1094. if(edit.GetModify())
  1095. {
  1096. int nRet = MessageBox("文件已经修改,需要保存吗?", "", MB_YESNOCANCEL|MB_ICONQUESTION);
  1097. if(nRet==IDYES)
  1098. {
  1099. if(!m_strFileName.IsEmpty())
  1100. {
  1101. SaveTheContext();
  1102. }
  1103. else
  1104. {
  1105. CFileDialog fd ( FALSE, _T(""), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("*.*|*.*||"));
  1106. if(fd.DoModal()==IDCANCEL)
  1107. return;
  1108. m_strFileName = fd.GetPathName();
  1109. SaveTheContext();
  1110. }
  1111. }
  1112. else if(nRet==IDCANCEL)
  1113. {
  1114. return;
  1115. }
  1116. }
  1117. CFrameWnd::OnClose();
  1118. }