MainFrm.cpp 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  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. int j = 0;
  740. for(; j<ncount; j++) {
  741. if(strline[j]!=0x20)
  742. break;
  743. }
  744. SynCtrl.SetSel(nselstart, nselstart+j);
  745. SynCtrl.ReplaceSel(_T(""), TRUE); //替换后可能引总行数减少
  746. }
  747. }
  748. int noldlinecount = SynCtrl.GetLineCount();
  749. int nnewlinecount = SynCtrl.GetLineCount();
  750. linenumber+=nnewlinecount-noldlinecount;
  751. }
  752. }
  753. int nselstart = SynCtrl.LineIndex(nfirstline);
  754. int nselend = SynCtrl.LineIndex(nfirstline+linenumber);
  755. SynCtrl.SetSel(nselstart, nselend);
  756. icrEditView->ShowWindow(SW_SHOW);
  757. }
  758. void CMainFrame::OnEditUncomment()
  759. {
  760. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  761. CRichEditCtrl &SynCtrl = icrEditView->GetRichEditCtrl();
  762. int nfirstline, nendline;
  763. icrEditView->GetSelLine(nfirstline, nendline);
  764. //取当前语言对应的单行注释字符串
  765. CString strsinglecomment=icrEditView->GetSingleCommentString(icrEditView->GetLanguage());
  766. if(strsinglecomment.IsEmpty()) //若为空串表示当前没有进行语法关键字显示
  767. return;
  768. CString strtext=_T(""), strline;
  769. icrEditView->ShowWindow(SW_HIDE);
  770. BOOL bpriorlinerealreturn;
  771. int linenumber = nendline - nfirstline + 1;
  772. for(int i=0; i<linenumber; i++) {
  773. if(nfirstline+i-1<0)//判断前一行行末是否是硬回车
  774. bpriorlinerealreturn = TRUE;
  775. else
  776. bpriorlinerealreturn = icrEditView->GetLineString(nfirstline+i-1, strline);
  777. icrEditView->GetLineString(nfirstline+i, strline);
  778. if(bpriorlinerealreturn || nfirstline==nendline) { //如果上一行是真的换行
  779. int nselstart = SynCtrl.LineIndex(nfirstline+i);
  780. SynCtrl.SetSel(nselstart, nselstart);
  781. if(strline!=_T(" ")) {
  782. if(strline.Left(strsinglecomment.GetLength())==strsinglecomment)
  783. SynCtrl.SetSel(nselstart, nselstart+strsinglecomment.GetLength());
  784. else {
  785. CString strtmp = strline;
  786. if(strtmp.GetLength()!=0) {
  787. while(strtmp.GetAt(0)==0x20 || strtmp.GetAt(0)=='\t') {
  788. strtmp.TrimLeft(0x20);
  789. strtmp.TrimLeft('\t');
  790. if(strtmp.GetLength()==0)
  791. break;
  792. }
  793. if(strtmp.GetLength()>=strsinglecomment.GetLength() ) {
  794. if(strtmp.Left(strsinglecomment.GetLength())==strsinglecomment) {
  795. int npos = strline.Find(strsinglecomment);
  796. SynCtrl.SetSel( nselstart+npos, nselstart+npos+strsinglecomment.GetLength());
  797. }
  798. }
  799. }
  800. }
  801. }
  802. int noldlinecount=SynCtrl.GetLineCount();
  803. SynCtrl.ReplaceSel(_T(""), TRUE); //此行可能引起总的行数减少
  804. int nnewlinecount=SynCtrl.GetLineCount();
  805. linenumber+=nnewlinecount-noldlinecount;
  806. }
  807. }
  808. int nselstart = SynCtrl.LineIndex(nfirstline);
  809. int nselend = SynCtrl.LineIndex(nfirstline+linenumber);
  810. SynCtrl.SetSel(nselstart, nselend);
  811. icrEditView->ShowWindow(SW_SHOW);
  812. }
  813. void CMainFrame::OnEditComment()
  814. {
  815. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  816. CRichEditCtrl &SynCtrl = icrEditView->GetRichEditCtrl();
  817. int nfirstline, nendline;
  818. icrEditView->GetSelLine(nfirstline, nendline);
  819. //取当前语言对应的单行注释字符串
  820. CString strsinglecomment=icrEditView->GetSingleCommentString(icrEditView->GetLanguage());
  821. if(strsinglecomment.IsEmpty()) //若为空串表示当前没有进行语法关键字显示
  822. return;
  823. icrEditView->ShowWindow(SW_HIDE);
  824. CString strtext=_T(""), strline;
  825. BOOL bpriorlinerealreturn;
  826. int linenumber = nendline - nfirstline + 1;
  827. for(int i=0; i<linenumber; i++) {
  828. if(nfirstline+i-1<0)//判断前一行行末是否是硬回车
  829. bpriorlinerealreturn = TRUE;
  830. else
  831. bpriorlinerealreturn = icrEditView->GetLineString(nfirstline+i-1, strline);
  832. icrEditView->GetLineString(nfirstline+i, strline);
  833. if(bpriorlinerealreturn || nfirstline==nendline) { //如果上一行是真的换行
  834. int nselstart = SynCtrl.LineIndex(nfirstline+i);
  835. SynCtrl.SetSel(nselstart, nselstart);
  836. int noldlinecount = SynCtrl.GetLineCount();
  837. SynCtrl.ReplaceSel(strsinglecomment, TRUE);
  838. int nnewlinecount = SynCtrl.GetLineCount();
  839. linenumber+=nnewlinecount-noldlinecount;
  840. }
  841. }
  842. int nselstart = SynCtrl.LineIndex(nfirstline);
  843. int nselend = SynCtrl.LineIndex(nfirstline+linenumber);
  844. SynCtrl.SetSel(nselstart, nselend);
  845. icrEditView->ShowWindow(SW_SHOW);
  846. }
  847. void CMainFrame::OnEditLcase()
  848. {
  849. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  850. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  851. CHARRANGE cr;
  852. edit.GetSel(cr);
  853. CString strsel;
  854. EDITSTREAM stream;
  855. stream.dwCookie = (DWORD)&strsel;
  856. stream.pfnCallback = EditStreamCallbackOut;
  857. edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
  858. strsel.MakeLower();
  859. edit.ReplaceSel(strsel, TRUE);
  860. edit.SetSel(cr);
  861. }
  862. void CMainFrame::OnEditUcase()
  863. {
  864. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  865. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  866. CHARRANGE cr;
  867. edit.GetSel(cr);
  868. CString strsel;
  869. EDITSTREAM stream;
  870. stream.dwCookie = (DWORD)&strsel;
  871. stream.pfnCallback = EditStreamCallbackOut;
  872. edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
  873. strsel.MakeUpper();
  874. edit.ReplaceSel(strsel, TRUE);
  875. edit.SetSel(cr);
  876. }
  877. void CMainFrame::OnEditInvert()
  878. {
  879. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  880. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  881. CHARRANGE cr;
  882. edit.GetSel(cr);
  883. CString strsel;
  884. EDITSTREAM stream;
  885. stream.dwCookie = (DWORD)&strsel;
  886. stream.pfnCallback = EditStreamCallbackOut;
  887. edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
  888. for(int i=0; i<strsel.GetLength(); i++) {
  889. TCHAR ch = strsel[i];
  890. if( ch >='A' && ch <='Z' )
  891. strsel.SetAt(i, ch + 'a' - 'A');
  892. else if( ch >='a' && ch <='z' )
  893. strsel.SetAt(i, ch + 'A' - 'a');
  894. }
  895. edit.ReplaceSel(strsel, TRUE);
  896. edit.SetSel(cr);
  897. }
  898. void CMainFrame::OnEditCapitalize()
  899. {
  900. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  901. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  902. CHARRANGE cr;
  903. edit.GetSel(cr);
  904. CString strsel;
  905. EDITSTREAM stream;
  906. stream.dwCookie = (DWORD)&strsel;
  907. stream.pfnCallback = EditStreamCallbackOut;
  908. edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
  909. strsel.MakeLower();
  910. BOOL bIsChar = FALSE, bInString=FALSE;
  911. for(int i=0; i<strsel.GetLength(); i++) {
  912. TCHAR ch = strsel[i];
  913. if( ch >='a' && ch <='z' && !bIsChar) {
  914. strsel.SetAt(i, ch + 'A' - 'a');
  915. }
  916. if( (ch >='a' && ch <='z') || (ch >='A' && ch <='Z') )
  917. bIsChar = TRUE;
  918. else
  919. bIsChar = FALSE;
  920. }
  921. edit.ReplaceSel(strsel, TRUE);
  922. edit.SetSel(cr);
  923. }
  924. void CMainFrame::OnEditSentancecase()
  925. {
  926. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  927. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  928. CHARRANGE cr;
  929. edit.GetSel(cr);
  930. CString strsel;
  931. EDITSTREAM stream;
  932. stream.dwCookie = (DWORD)&strsel;
  933. stream.pfnCallback = EditStreamCallbackOut;
  934. edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
  935. BOOL bDo = TRUE;
  936. for(int i=0; i<strsel.GetLength(); i++) {
  937. TCHAR ch = strsel[i];
  938. if(ch == 0xa)
  939. bDo = TRUE;
  940. if( ((ch >='a' && ch <='z') || (ch >='A' && ch <='Z')) && bDo) {
  941. if( ch >='A' && ch <='Z' )
  942. strsel.SetAt(i, ch + 'a' - 'A');
  943. else
  944. strsel.SetAt(i, ch + 'A' - 'a');
  945. bDo = FALSE;
  946. }
  947. }
  948. edit.ReplaceSel(strsel, TRUE);
  949. edit.SetSel(cr);
  950. }
  951. CString CMainFrame::GetFileContext(CString strfile)
  952. {
  953. CString str=_T("");;
  954. CFileException fe;
  955. CFile file;
  956. file.Open(strfile, CFile::modeRead, &fe);
  957. if(fe.m_cause != CFileException::none) {
  958. fe.ReportError();
  959. return _T("");
  960. }
  961. DWORD dwSize=(DWORD)file.GetLength();
  962. if(dwSize==0)
  963. return _T("");
  964. try {
  965. LPSTR lpszContext=new TCHAR[1];
  966. file.Read(lpszContext, 1);
  967. if(*lpszContext==-1) {
  968. if(lpszContext!=NULL)
  969. delete lpszContext;
  970. LPWSTR lpsztext= new WCHAR[1];
  971. file.Read(lpsztext, 1);
  972. if(lpsztext!=NULL)
  973. delete lpsztext;
  974. lpsztext= new WCHAR[dwSize-1];
  975. DWORD dwRead=file.Read(lpsztext, dwSize-2);
  976. lpsztext[dwRead/2]=0;
  977. str=lpsztext;
  978. if(lpsztext!=NULL)
  979. delete lpsztext;
  980. }
  981. else {
  982. if(lpszContext!=NULL)
  983. delete lpszContext;
  984. lpszContext=new TCHAR[dwSize+2];
  985. file.Seek(0, CFile::begin);
  986. DWORD dwRead=file.Read(lpszContext, dwSize);
  987. file.Close();
  988. lpszContext[dwRead]='\0';
  989. str=lpszContext;
  990. if(lpszContext!=NULL)
  991. delete lpszContext;
  992. }
  993. }
  994. catch(...){}
  995. return str;
  996. }
  997. void CMainFrame::OnSelchangeComboFind()
  998. {
  999. }
  1000. void CMainFrame::OnUpdateEditLcase(CCmdUI* pCmdUI)
  1001. {
  1002. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  1003. CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
  1004. CHARRANGE cr;
  1005. editctrl.GetSel(cr);
  1006. pCmdUI->Enable(cr.cpMin!=cr.cpMax);
  1007. }
  1008. void CMainFrame::OnUpdateEditInvert(CCmdUI* pCmdUI)
  1009. {
  1010. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  1011. CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
  1012. CHARRANGE cr;
  1013. editctrl.GetSel(cr);
  1014. pCmdUI->Enable(cr.cpMin!=cr.cpMax);
  1015. }
  1016. void CMainFrame::OnUpdateEditSentancecase(CCmdUI* pCmdUI)
  1017. {
  1018. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  1019. CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
  1020. CHARRANGE cr;
  1021. editctrl.GetSel(cr);
  1022. pCmdUI->Enable(cr.cpMin!=cr.cpMax);
  1023. }
  1024. void CMainFrame::OnUpdateEditUcase(CCmdUI* pCmdUI)
  1025. {
  1026. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  1027. CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
  1028. CHARRANGE cr;
  1029. editctrl.GetSel(cr);
  1030. pCmdUI->Enable(cr.cpMin!=cr.cpMax);
  1031. }
  1032. void CMainFrame::OnFileNew()
  1033. {
  1034. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  1035. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  1036. if(!m_strFileName.IsEmpty())
  1037. {
  1038. if(edit.GetModify())
  1039. {
  1040. if(MessageBox("文件已经修改,需要保存吗?", "", MB_YESNO|MB_ICONQUESTION)==IDYES)
  1041. {
  1042. SaveTheContext();
  1043. }
  1044. }
  1045. }
  1046. edit.SetWindowText("");
  1047. m_strFileName = "";
  1048. icrEditView->SetSynEditViewFont(icrEditView->GetSynEditViewFont());
  1049. }
  1050. void CMainFrame::OnFileSaveAs()
  1051. {
  1052. if(m_strFileName.IsEmpty())
  1053. {
  1054. CFileDialog fd ( FALSE, _T(""), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("*.srp|*.srp||"));
  1055. if(fd.DoModal()==IDCANCEL)
  1056. return;
  1057. m_strFileName = fd.GetPathName();
  1058. }
  1059. else
  1060. {
  1061. CString strFileName = m_strFileName;
  1062. int nPos= strFileName.ReverseFind('\\');
  1063. strFileName = strFileName.Right(strFileName.GetLength()-nPos-1);
  1064. CFileDialog fd ( FALSE, "", NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("*.srp|*.srp||"));
  1065. wsprintf(fd.m_ofn.lpstrFile, strFileName);
  1066. if(fd.DoModal()==IDCANCEL)
  1067. return;
  1068. m_strFileName = fd.GetPathName();
  1069. }
  1070. SaveTheContext();
  1071. }
  1072. void CMainFrame::OnFilesave()
  1073. {
  1074. if(m_strFileName.IsEmpty())
  1075. {
  1076. CFileDialog fd ( FALSE, _T(""), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("*.srp|*.srp||"));
  1077. if(fd.DoModal()==IDCANCEL)
  1078. return;
  1079. m_strFileName = fd.GetPathName();
  1080. }
  1081. SaveTheContext();
  1082. }
  1083. void CMainFrame::OnUpdateEditCapitalize(CCmdUI* pCmdUI)
  1084. {
  1085. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  1086. CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
  1087. CHARRANGE cr;
  1088. editctrl.GetSel(cr);
  1089. pCmdUI->Enable(cr.cpMin!=cr.cpMax);
  1090. }
  1091. void CMainFrame::OnClose()
  1092. {
  1093. CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
  1094. CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
  1095. if(edit.GetModify())
  1096. {
  1097. int nRet = MessageBox("文件已经修改,需要保存吗?", "", MB_YESNOCANCEL|MB_ICONQUESTION);
  1098. if(nRet==IDYES)
  1099. {
  1100. if(!m_strFileName.IsEmpty())
  1101. {
  1102. SaveTheContext();
  1103. }
  1104. else
  1105. {
  1106. CFileDialog fd ( FALSE, _T(""), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("*.*|*.*||"));
  1107. if(fd.DoModal()==IDCANCEL)
  1108. return;
  1109. m_strFileName = fd.GetPathName();
  1110. SaveTheContext();
  1111. }
  1112. }
  1113. else if(nRet==IDCANCEL)
  1114. {
  1115. return;
  1116. }
  1117. }
  1118. CFrameWnd::OnClose();
  1119. }