📄 gview.cpp
字号:
// gView.cpp : implementation of the CGView class
//
#include "stdafx.h"
#include "g.h"
#include "gDoc.h"
#include "CntrItem.h"
#include "gView.h"
#include "mainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGView
IMPLEMENT_DYNCREATE(CGView, CRichEditView)
BEGIN_MESSAGE_MAP(CGView, CRichEditView)
//{{AFX_MSG_MAP(CGView)
ON_WM_SETCURSOR()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
ON_COMMAND(IDC_CLEARRICH, OnClearrich)
ON_WM_RBUTTONDOWN()
ON_COMMAND(IDM_COLOR, OnColor)
ON_COMMAND(IDM_BACKGROUND, OnBackground)
ON_COMMAND(IDM_RAW, OnRaw)
ON_UPDATE_COMMAND_UI(IDM_RAW, OnUpdateRaw)
ON_COMMAND(IDM_FILE_OPEN, OnFileOpen)
ON_COMMAND(IDM_FILE_SAVE, OnFileSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGView construction/destruction
CGView::CGView()
{
m_nMaxLine=-1;
m_bRaw=FALSE;
}
CGView::~CGView()
{
}
BOOL CGView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRichEditView::PreCreateWindow(cs);
}
void CGView::OnInitialUpdate()
{
CRichEditView::OnInitialUpdate();
CWinApp* pApp = AfxGetApp();
m_crBk = pApp->GetProfileInt("sys","bkColor",0);
m_nMaxLine = pApp->GetProfileInt("sys","maxLine",-1);
m_ansi.m_color = pApp->GetProfileInt("sys","color", RGB(128, 128, 128));
m_ansi.Init(&GetRichEditCtrl());
GetRichEditCtrl().SetBackgroundColor(0, 0);
}
/////////////////////////////////////////////////////////////////////////////
// CGView diagnostics
#ifdef _DEBUG
void CGView::AssertValid() const
{
CRichEditView::AssertValid();
}
void CGView::Dump(CDumpContext& dc) const
{
CRichEditView::Dump(dc);
}
CGDoc* CGView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGDoc)));
return (CGDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGView message handlers
void CGView::Display(LPCTSTR s)
{
CRichEditCtrl* p=&GetRichEditCtrl();
CString temp;
if(m_nMaxLine>0&&p->GetLineCount()>m_nMaxLine)
{
p->SetSel(0,p->LineIndex(m_nMaxLine/10+1));
p->ReplaceSel("");
}
if (m_bRaw)
{
p->SetSel(-1, -1);
p->ReplaceSel(s);
}
else
m_ansi.Dispaly((LPTSTR)s);
}
BOOL CGView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
return TRUE;
// return CRichEditView::OnSetCursor(pWnd, nHitTest, message);
}
void CGView::OnLButtonDown(UINT nFlags, CPoint point)
{
CRichEditView::OnLButtonDown(nFlags, point);
CString s=GetText();
if(!s.IsEmpty())
{
CMainFrame* pFrame=(CMainFrame*)GetParentFrame();
pFrame->SetWhoEdit(s);
}
}
CString CGView::GetText()
{
CRichEditCtrl* p=&GetRichEditCtrl();
long a,b;
char s[256];
p->GetSel(a,b);
int n,m,k=p->LineFromChar(a);
n=p->GetLine(k,s,256);
s[n]=0;
k=p->LineIndex(k);
CString ss(s);
n=ss.Find("(");
if (n != -1)
{
m=ss.Find(")",n);
if(m!=-1 && k+n<a && a<=k+m)
{
p->SetSel(k+n+1,k+m);
ss=ss.Mid(n+1,m-n-1);
p->Copy();
}
}
else
ss.Empty();
return ss;
}
void CGView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CRichEditView::OnLButtonDblClk(nFlags, point);
CGDoc* pDoc=(CGDoc*)GetDocument();
CRichEditCtrl* p=&GetRichEditCtrl();
// p->Paste();
pDoc->SendCmd(p->GetSelText());
}
void CGView::OnClearrich()
{
GetRichEditCtrl().SetWindowText("");
}
void CGView::OnRButtonDown(UINT nFlags, CPoint point)
{
CRichEditView::OnRButtonDown(nFlags, point);
CRichEditCtrl* p=&GetRichEditCtrl();
if(p->GetSelectionType()!=SEL_EMPTY)
p->Copy();
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
pFrame->Paste();
}
void CGView::OnColor()
{
CHARFORMAT cf;
GetRichEditCtrl().GetDefaultCharFormat(cf);
CFontDialog dlg(cf);
if(dlg.DoModal())
{
dlg.GetCharFormat(cf);
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_SIZE|CFM_FACE|CFM_BOLD|CFM_ITALIC|CFM_COLOR
|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_CHARSET;
GetRichEditCtrl().SetDefaultCharFormat(cf);
m_ansi.m_color = dlg.m_cf.rgbColors;
CWinApp* pApp = AfxGetApp();
pApp->WriteProfileInt("sys","color",(int)cf.crTextColor);
pApp->WriteProfileInt("sys","fontSize",(int)cf.yHeight);
}
}
void CGView::OnBackground()
{
CColorDialog dlg(m_crBk);
if(dlg.DoModal()==IDOK)
{
m_crBk=dlg.GetColor();
GetRichEditCtrl().SetBackgroundColor(0,m_crBk);
}
}
void CGView::OnRaw()
{
m_bRaw=!m_bRaw;
CRichEditCtrl* p=&GetRichEditCtrl();
p->SetReadOnly(!m_bRaw);
}
void CGView::OnUpdateRaw(CCmdUI* pCmdUI)
{
pCmdUI->Enable();
pCmdUI->SetCheck(m_bRaw);
}
void CGView::OnFileOpen()
{
CFileDialog dlg(TRUE,NULL,NULL,OFN_NOCHANGEDIR|OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT);
if(dlg.DoModal()==IDOK)
{
CStdioFile file(dlg.GetPathName(),CFile::modeRead);
CString s,ss;
CRichEditCtrl* p=&GetRichEditCtrl();
p->SetWindowText("");
while(file.ReadString(s))
ss+=s+"\n";
Display(ss);
file.Close();
}
}
void CGView::OnFileSave()
{
CFileDialog dlg(FALSE,NULL,NULL,OFN_NOCHANGEDIR|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT);
if(dlg.DoModal()==IDOK)
{
CStdioFile file(dlg.GetPathName(),CFile::modeCreate|CFile::modeWrite);
CString s;
CRichEditCtrl* p=&GetRichEditCtrl();
p->GetWindowText(s);
file.WriteString(s);
file.Close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -