📄 scintillamfcview.cpp
字号:
/* @doc
* @module scintillamfcView.cpp | Implementation of a Scintilla syntax coloring view for MFC
*/
#include "stdafx.h"
#include "scintillamfc.h"
#include "scintillamfcDoc.h"
#include "scintillamfcView.h"
#include "wordlistdlg.h"
#include "GotoLineDlg.h"
#include "GotoPosDlg.h"
#include "ScintillaDlg.h"
#include "scintilla\include\scintilla.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CScintillamfcView
IMPLEMENT_DYNCREATE(CScintillamfcView, CView)
BEGIN_MESSAGE_MAP(CScintillamfcView, CView)
//{{AFX_MSG_MAP(CScintillamfcView)
ON_WM_CREATE()
ON_WM_SIZE()
ON_COMMAND(ID_OPTIONS_VIEW_LINENUMBERS, OnOptionsViewLinenumbers)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_VIEW_LINENUMBERS, OnUpdateOptionsViewLinenumbers)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
ON_COMMAND(ID_EDIT_CUT, OnEditCut)
ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_LINE, OnUpdateLine)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_STYLE, OnUpdateStyle)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_FOLD, OnUpdateFold)
ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo)
ON_COMMAND(ID_EDIT_SELECT_ALL, OnEditSelectAll)
ON_COMMAND(ID_OPTIONS_SETFONT, OnOptionsSetfont)
ON_COMMAND(ID_OPTIONS_FOREGROUND, OnOptionsForeground)
ON_COMMAND(ID_OPTIONS_BACKGROUND, OnOptionsBackground)
ON_COMMAND(ID_OPTIONS_WORDLIST, OnOptionsWordlist)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_OVR, OnUpdateInsert)
ON_COMMAND(ID_TOGGLE_INSERT, OnToggleInsert)
ON_COMMAND(ID_OPTIONS_FOLD_MARGIN, OnOptionsFoldMargin)
ON_COMMAND(ID_OPTIONS_SELECTION_MARGIN, OnOptionsSelectionMargin)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_SELECTION_MARGIN, OnUpdateOptionsSelectionMargin)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_FOLD_MARGIN, OnUpdateOptionsFoldMargin)
ON_COMMAND(ID_OPTIONS_ADDMARKER, OnOptionsAddmarker)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_ADDMARKER, OnUpdateOptionsAddmarker)
ON_COMMAND(ID_OPTIONS_DELETEMARKER, OnOptionsDeletemarker)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_DELETEMARKER, OnUpdateOptionsDeletemarker)
ON_COMMAND(ID_OPTIONS_FIND_NEXTMARKER, OnOptionsFindNextmarker)
ON_COMMAND(ID_OPTIONS_FIND_PREVMARKER, OnOptionsFindPrevmarker)
ON_COMMAND(ID_OPTIONS_GOTOPOS, OnOptionsGotopos)
ON_COMMAND(ID_OPTIONS_GOTOLINE, OnOptionsGotoline)
ON_COMMAND(ID_OPTIONS_DLG, OnOptionsDlg)
//}}AFX_MSG_MAP
// Standard-Druckbefehle
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////
// @mfunc constructor
// @rvalue void | not used
//
CScintillamfcView::CScintillamfcView()
{
}
/////////////////////////////////////
// @mfunc destructor
// @rvalue void | not used
//
CScintillamfcView::~CScintillamfcView()
{
}
/////////////////////////////////////
// @mfunc called before window is created
// @rvalue void | not used
//
BOOL CScintillamfcView::PreCreateWindow(CREATESTRUCT& cs)
{
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////
// @mfunc Called when view should be redrawn - not used - handled by scintilla window
// @rvalue void | not used
//
void CScintillamfcView::OnDraw(CDC* pDC)
{
CScintillamfcDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
}
/////////////////////////////////////
// @mfunc not handled
// @rvalue void | not used
//
BOOL CScintillamfcView::OnPreparePrinting(CPrintInfo* pInfo)
{
return DoPreparePrinting(pInfo);
}
/////////////////////////////////////
// @mfunc not handled
// @rvalue void | not used
//
void CScintillamfcView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
}
/////////////////////////////////////
// @mfunc not handled
// @rvalue void | not used
//
void CScintillamfcView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
}
#ifdef _DEBUG
void CScintillamfcView::AssertValid() const
{
CView::AssertValid();
}
void CScintillamfcView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
/////////////////////////////////////
// @mfunc return document handle
// @rvalue void | not used
//
CScintillamfcDoc* CScintillamfcView::GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CScintillamfcDoc)));
return (CScintillamfcDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////
// @mfunc Called when window is created - we create our scintilla window here
// @rvalue int | 0 on succescc else -1
//
int CScintillamfcView::OnCreate(
LPCREATESTRUCT lpCreateStruct) //@parm pointer to propsed create structure - may be modified
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndScintilla.Create(_T("Title"), WS_CHILD | WS_VISIBLE, CRect(0,0,0,0), this, 10000)) // hb - todo autogenerate id
{
LPVOID lpMsgBuf;
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf,0,NULL);
// Write to stderr
TRACE (_T("%s\n"), (LPCTSTR)lpMsgBuf);
// Free the buffer.
LocalFree( lpMsgBuf );
return -1;
}
return 0;
}
/////////////////////////////////////
// @mfunc Called when view is resized - we adjust the size of the scintilla window to fit client size
// @rvalue void | not used
//
void CScintillamfcView::OnSize(
UINT nType, //@parm indicator
int cx, //@parm new width in pixel
int cy) //@parm new height in pixel
{
CView::OnSize(nType, cx, cy);
if (m_wndScintilla.GetSafeHwnd())
{
m_wndScintilla.MoveWindow(0, 0, cx, cy);
}
}
/////////////////////////////////////
// @mfunc Called when view was created - we try to let scintilla load a file if there is one
// @rvalue void | not used
//
void CScintillamfcView::OnInitialUpdate()
{
CView::OnInitialUpdate();
CDocument *pDoc = GetDocument();
CString strTitle = pDoc->GetPathName();
m_wndScintilla.Init();
m_wndScintilla.LoadFile(strTitle);
}
/////////////////////////////////////
// @mfunc menu handler - toggle display of the line number display in scintilla
// @rvalue void | not used
//
void CScintillamfcView::OnOptionsViewLinenumbers()
{
m_wndScintilla.SetDisplayLinenumbers(!m_wndScintilla.GetDisplayLinenumbers());
}
/////////////////////////////////////
// @mfunc menu check handler - check the menu item if line numbers are displayed
// @rvalue void | not used
//
void CScintillamfcView::OnUpdateOptionsViewLinenumbers(
CCmdUI* pCmdUI) //@parm menu handle
{
pCmdUI->SetCheck(m_wndScintilla.GetDisplayLinenumbers());
}
/////////////////////////////////////
// @mfunc menu handler - copy selected text to clipboard
// @rvalue void | not used
//
void CScintillamfcView::OnEditCopy()
{
m_wndScintilla.Copy();
}
/////////////////////////////////////
// @mfunc menu check handler - do nothing
// @rvalue void | not used
//
void CScintillamfcView::OnUpdateEditCopy(
CCmdUI* pCmdUI) //@parm menu handle
{
}
/////////////////////////////////////
// @mfunc menu handler - cut selected text to clipboard
// @rvalue void | not used
//
void CScintillamfcView::OnEditCut()
{
m_wndScintilla.Cut();
}
/////////////////////////////////////
// @mfunc menu check handler - do nothing
// @rvalue void | not used
//
void CScintillamfcView::OnUpdateEditCut(
CCmdUI* pCmdUI) //@parm menu handle
{
}
/////////////////////////////////////
// @mfunc menu handler - paste text from clipboard
// @rvalue void | not used
//
void CScintillamfcView::OnEditPaste()
{
m_wndScintilla.Paste();
}
/////////////////////////////////////
// @mfunc menu check handler - check if there is somethiong to paste
// @rvalue void | not used
//
void CScintillamfcView::OnUpdateEditPaste(
CCmdUI* pCmdUI) //@parm menu handle
{
pCmdUI->Enable(m_wndScintilla.CanPaste());
}
/////////////////////////////////////
// @mfunc menu handler - undo last action if possible
// @rvalue void | not used
//
void CScintillamfcView::OnEditUndo()
{
if (m_wndScintilla.CanUndo())
m_wndScintilla.Undo();
}
/////////////////////////////////////
// @mfunc menu check handler - check if there is an action to undo
// @rvalue void | not used
//
void CScintillamfcView::OnUpdateEditUndo(
CCmdUI* pCmdUI) //@parm menu handle
{
pCmdUI->Enable(m_wndScintilla.CanUndo());
}
/////////////////////////////////////
// @mfunc update line number
// @rvalue void | not used
//
void CScintillamfcView::OnUpdateLine(
CCmdUI* pCmdUI) //@parm handle of textpane for linenumbers - see mainfrm.cpp at top
{
CString strLine;
long lLine = m_wndScintilla.GetCurrentLine();
long lColumn = m_wndScintilla.GetCurrentColumn();
long lPos = m_wndScintilla.GetCurrentPosition();
strLine.Format(IDS_LINE_INDICATOR, lLine, lColumn, lPos);
pCmdUI->SetText(strLine);
}
/////////////////////////////////////
// @mfunc update style number
// @rvalue void | not used
//
void CScintillamfcView::OnUpdateStyle(
CCmdUI* pCmdUI) //@parm handle of textpane for style number - see mainfrm.cpp at top
{
CString strLine;
int nStyle = m_wndScintilla.GetCurrentStyle();
strLine.Format(IDS_STYLE_INDICATOR, nStyle);
pCmdUI->SetText(strLine);
}
/////////////////////////////////////
// @mfunc update folding level
// @rvalue void | not used
//
void CScintillamfcView::OnUpdateFold(
CCmdUI* pCmdUI) //@parm handle of textpane for folding level - see mainfrm.cpp at top
{
CString strLine;
int nFold = m_wndScintilla.GetCurrentFoldinglevel();
strLine.Format(IDS_FOLD_INDICATOR, nFold);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -