📄 cedtviewevent.cpp
字号:
#include "stdafx.h"
#include "cedtHeader.h"
BOOL CCedtView::EventMoveCaret(UINT nChar, UINT nFlags, BOOL bMacro)
{
BOOL bShift = nFlags & KEYSTATE_SHIFT;
BOOL bRedraw = FALSE;
if( ! m_bSelected && bShift ) {
m_nAnchorPosX = m_nCaretPosX;
m_nAnchorPosY = m_nCaretPosY;
}
INT nBegX, nBegY, nEndX, nEndY;
if( m_bSelected ) GetSelectedPosition( nBegX, nBegY, nEndX, nEndY );
switch( nChar ) {
case VK_LEFT:
if( m_bSelected && ! bShift ) { SetCaretPosY( nBegY ); SetCaretPosX( nBegX ); }
else bRedraw = ActionMoveLeft(nFlags);
break;
case VK_RIGHT:
if( m_bSelected && ! bShift ) { SetCaretPosY( nEndY ); SetCaretPosX( nEndX ); }
else bRedraw = ActionMoveRight(nFlags);
break;
case VK_UP:
if( m_bSelected && ! bShift ) { SetCaretPosY( nBegY ); SetCaretPosX( nBegX ); }
bRedraw = ActionMoveUp(nFlags);
break;
case VK_DOWN:
if( m_bSelected && ! bShift ) { SetCaretPosY( nEndY ); SetCaretPosX( nEndX ); }
bRedraw = ActionMoveDown(nFlags);
break;
case VK_HOME:
if( m_bSelected && ! bShift ) { SetCaretPosY( nBegY ); SetCaretPosX( nBegX ); }
bRedraw = ActionMoveHome(nFlags);
break;
case VK_END:
if( m_bSelected && ! bShift ) { SetCaretPosY( nEndY ); SetCaretPosX( nEndX ); }
bRedraw = ActionMoveEnd(nFlags);
break;
case VK_PRIOR:
if( m_bSelected && ! bShift ) { SetCaretPosY( nBegY ); SetCaretPosX( nBegX ); }
bRedraw = ActionMovePrior(nFlags);
break;
case VK_NEXT:
if( m_bSelected && ! bShift ) { SetCaretPosY( nEndY ); SetCaretPosX( nEndX ); }
bRedraw = ActionMoveNext(nFlags);
break;
}
if( bShift ) {
m_bSelected = ( (m_nAnchorPosY != m_nCaretPosY) || (m_nAnchorPosX != m_nCaretPosX) );
bRedraw = TRUE;
} else if( m_bSelected ) {
m_bSelected = FALSE;
bRedraw = TRUE;
}
return bRedraw;
}
void CCedtView::EventInsertChar(UINT nChar, BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected && m_nCaretPosX != m_nAnchorPosX ) { ActionDeleteColumnSelection(); m_bSelected = (m_nCaretPosY != m_nAnchorPosY); }
if( m_bSelected ) ActionInsertColumnChar( nChar );
else ActionInsertChar( nChar );
} else {
if( m_bSelected ) { ActionDeleteLineSelection(); m_bSelected = FALSE; }
ActionInsertChar( nChar );
}
}
void CCedtView::EventInsertString(LPCTSTR lpszString, BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected ) {
if( m_nCaretPosX != m_nAnchorPosX ) ActionDeleteColumnSelection();
m_bSelected = FALSE;
}
ActionInsertString( lpszString );
} else {
if( m_bSelected ) { ActionDeleteLineSelection(); m_bSelected = FALSE; }
ActionInsertString( lpszString );
}
}
void CCedtView::EventInsertFile(LPCTSTR lpszPathName, BOOL bMacro)
{
CMemText Block; Block.FileLoad( lpszPathName );
if( m_bColumnMode ) {
if( m_bSelected ) {
if( m_nCaretPosX != m_nAnchorPosX ) ActionDeleteColumnSelection();
m_bSelected = FALSE;
}
ActionPasteColumnSelection( Block );
} else {
if( m_bSelected ) { ActionDeleteLineSelection(); m_bSelected = FALSE; }
ActionPasteLineSelection( Block );
}
}
void CCedtView::EventCompositionStart(BOOL bMacro)
{
ActionCompositionStart();
}
void CCedtView::EventCompositionEnd(BOOL bMacro)
{
ActionCompositionEnd();
}
void CCedtView::EventCompositionCompose(LPCTSTR lpszString, BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected ) {
if( m_nCaretPosX != m_nAnchorPosX ) ActionDeleteColumnSelection();
m_bSelected = FALSE;
}
ActionCompositionCompose(lpszString);
} else {
if( m_bSelected ) { ActionDeleteLineSelection(); m_bSelected = FALSE; }
ActionCompositionCompose(lpszString);
}
}
void CCedtView::EventCompositionResult(LPCTSTR lpszString, BOOL bMacro)
{
// there should no selection before this function call
ActionCompositionResult(lpszString);
}
void CCedtView::EventCommandEscape(BOOL bMacro)
{
// just release current selection
if( m_bSelected ) m_bSelected = FALSE;
}
void CCedtView::EventCommandReturn(BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected ) {
if( m_nCaretPosX == m_nAnchorPosX ) { ActionWrongOperation(! bMacro); m_bSelected = TRUE; }
else { ActionDeleteColumnSelection(); m_bSelected = (m_nCaretPosY != m_nAnchorPosY); }
} else ActionCarrigeReturn();
} else {
if( m_bSelected ) { ActionDeleteLineSelection(); m_bSelected = FALSE; }
ActionCarrigeReturn();
}
}
void CCedtView::EventCommandBack(BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected ) {
if( m_nCaretPosX == m_nAnchorPosX ) { ActionDeleteColumnPrevChar(); m_bSelected = TRUE; }
else { ActionDeleteColumnSelection(); m_bSelected = (m_nCaretPosY != m_nAnchorPosY); }
} else ActionBackspace();
} else {
if( m_bSelected ) { ActionDeleteLineSelection(); m_bSelected = FALSE; }
else ActionBackspace();
}
}
void CCedtView::EventCommandDelete(BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected ) {
if( m_nCaretPosX == m_nAnchorPosX ) { ActionDeleteColumnChar(); m_bSelected = TRUE; }
else { ActionDeleteColumnSelection(); m_bSelected = (m_nCaretPosY != m_nAnchorPosY); }
} else ActionDeleteChar();
} else {
if( m_bSelected ) { ActionDeleteLineSelection(); m_bSelected = FALSE; }
else ActionDeleteChar();
}
}
void CCedtView::EventCommandTab(BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected ) {
if( m_nCaretPosX != m_nAnchorPosX ) ActionDeleteColumnSelection();
if( m_bUseSpacesInPlaceOfTab ) ActionInsertColumnSpacesInPlaceOfTab();
else ActionInsertColumnChar('\t');
m_bSelected = (m_nCaretPosY != m_nAnchorPosY);
} else {
if( m_bUseSpacesInPlaceOfTab ) ActionInsertSpacesInPlaceOfTab();
else ActionInsertChar('\t');
}
} else {
if( ! GetSelectedLineCount() ) {
if( m_bSelected ) { ActionDeleteLineSelection(); m_bSelected = FALSE; }
if( m_bUseSpacesInPlaceOfTab ) ActionInsertSpacesInPlaceOfTab();
else ActionInsertChar('\t');
} else ActionIndentLineSelection();
}
}
void CCedtView::EventCommandDetab(BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected ) m_bSelected = FALSE;
ActionDetabCaret();
} else {
if( ! GetSelectedLineCount() ) {
if( m_bSelected ) m_bSelected = FALSE;
ActionDetabCaret();
} else ActionUnindentLineSelection();
}
}
void CCedtView::EventIncreaseIndent(BOOL bMacro)
{
if( ! m_bColumnMode ) {
if( ! GetSelectedLineCount() ) {
if( m_bSelected ) m_bSelected = FALSE;
ActionIndentLine();
} else ActionIndentLineSelection();
} else ActionWrongOperation(! bMacro);
}
void CCedtView::EventDecreaseIndent(BOOL bMacro)
{
if( ! m_bColumnMode ) {
if( ! GetSelectedLineCount() ) {
if( m_bSelected ) m_bSelected = FALSE;
ActionUnindentLine();
} else ActionUnindentLineSelection();
} else ActionWrongOperation(! bMacro);
}
void CCedtView::EventMakeComment(BOOL bMacro)
{
CCedtDoc * pDoc = (CCedtDoc *)GetDocument();
if( pDoc->HasLineCommentDelimiter() ) {
if( ! m_bColumnMode ) {
if( ! GetSelectedLineCount() ) {
if( m_bSelected ) m_bSelected = FALSE;
ActionMakeCommentLine();
} else ActionMakeCommentLineSelection();
} else ActionWrongOperation(! bMacro);
} else ActionWrongOperation(! bMacro);
}
void CCedtView::EventReleaseComment(BOOL bMacro)
{
CCedtDoc * pDoc = (CCedtDoc *)GetDocument();
if( pDoc->HasLineCommentDelimiter() ) {
if( ! m_bColumnMode ) {
if( ! GetSelectedLineCount() ) {
if( m_bSelected ) m_bSelected = FALSE;
ActionReleaseCommentLine();
} else ActionReleaseCommentLineSelection();
} else ActionWrongOperation(! bMacro);
} else ActionWrongOperation(! bMacro);
}
void CCedtView::EventJoinLines(BOOL bMacro)
{
// we need to expand this function to join multiple lines
if( m_bSelected ) m_bSelected = FALSE;
ActionJoinLines();
}
void CCedtView::EventSplitLine(BOOL bMacro)
{
// we need to expand this function to split multiple lines
if( m_bSelected ) m_bSelected = FALSE;
ActionSplitLine();
}
void CCedtView::EventDeleteWord(BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected ) {
if( m_nCaretPosX == m_nAnchorPosX ) { ActionDeleteColumnChar(); m_bSelected = TRUE; }
else { ActionDeleteColumnSelection(); m_bSelected = (m_nCaretPosY != m_nAnchorPosY); }
} else ActionDeleteWord();
} else {
if( m_bSelected ) { ActionDeleteLineSelection(); m_bSelected = FALSE; }
else ActionDeleteWord();
}
}
void CCedtView::EventDeletePrevWord(BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected ) {
if( m_nCaretPosX == m_nAnchorPosX ) { ActionDeleteColumnPrevChar(); m_bSelected = TRUE; }
else { ActionDeleteColumnSelection(); m_bSelected = (m_nCaretPosY != m_nAnchorPosY); }
} else ActionDeletePrevWord();
} else {
if( m_bSelected ) { ActionDeleteLineSelection(); m_bSelected = FALSE; }
else ActionDeletePrevWord();
}
}
void CCedtView::EventDeleteToEndOfLine(BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected ) {
if( m_nCaretPosX == m_nAnchorPosX ) { ActionDeleteColumnToEndOfLine(); m_bSelected = TRUE; }
else { ActionDeleteColumnSelection(); m_bSelected = (m_nCaretPosY != m_nAnchorPosY); }
} else ActionDeleteToEndOfLine();
} else {
if( m_bSelected ) { ActionDeleteLineSelection(); m_bSelected = FALSE; }
else ActionDeleteToEndOfLine();
}
}
void CCedtView::EventDeleteToBeginOfLine(BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected ) {
if( m_nCaretPosX == m_nAnchorPosX ) { ActionDeleteColumnToBeginOfLine(); m_bSelected = TRUE; }
else { ActionDeleteColumnSelection(); m_bSelected = (m_nCaretPosY != m_nAnchorPosY); }
} else ActionDeleteToBeginOfLine();
} else {
if( m_bSelected ) { ActionDeleteLineSelection(); m_bSelected = FALSE; }
else ActionDeleteToBeginOfLine();
}
}
void CCedtView::EventDeleteLine(BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected ) {
if( m_nCaretPosX == m_nAnchorPosX ) ActionWrongOperation(! bMacro);
else { ActionDeleteColumnSelection(); m_bSelected = (m_nCaretPosY != m_nAnchorPosY); }
} else ActionDeleteLine();
} else {
if( m_bSelected ) { ActionDeleteLineSelection(); m_bSelected = FALSE; }
else ActionDeleteLine();
}
}
void CCedtView::EventDuplicateLine(BOOL bMacro)
{
if( m_bSelected ) m_bSelected = FALSE;
ActionDuplicateLine();
}
void CCedtView::EventCommandCut(BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected ) {
if( m_nCaretPosX != m_nAnchorPosX ) {
CMemText Block; ActionCopyColumnSelection( Block );
ActionDeleteColumnSelection();
SetClipboardData( Block );
m_bSelected = (m_nCaretPosY != m_nAnchorPosY);
} else ActionWrongOperation(! bMacro);
} else ActionWrongOperation(! bMacro);
} else {
if( m_bSelected ) {
CMemText Block; ActionCopyLineSelection( Block );
ActionDeleteLineSelection();
SetClipboardData( Block );
m_bSelected = FALSE;
} else {
CMemText Block; ActionCopyLine( Block );
ActionDeleteLine();
SetClipboardData( Block );
}
}
}
void CCedtView::EventCommandCopy(BOOL bMacro)
{
if( m_bColumnMode ) {
if( m_bSelected ) {
if( m_nCaretPosX != m_nAnchorPosX ) {
CMemText Block; ActionCopyColumnSelection( Block );
SetClipboardData( Block );
} else ActionWrongOperation(! bMacro);
} else ActionWrongOperation(! bMacro);
} else {
if( m_bSelected ) {
CMemText Block; ActionCopyLineSelection( Block );
SetClipboardData( Block );
} else {
CMemText Block; ActionCopyLine( Block );
SetClipboardData( Block );
}
}
}
void CCedtView::EventCommandCopyFilePath(BOOL bMacro)
{
CMemText Block; ActionCopyFilePath( Block );
SetClipboardData( Block );
}
void CCedtView::EventCommandCutAppend(BOOL bMacro)
{
CMemText Block; GetClipboardData( Block );
if( ! m_bColumnMode ) {
if( m_bSelected ) {
CMemText Blck2; ActionCopyLineSelection( Blck2 );
ActionDeleteLineSelection();
Block.AppendText( Blck2 );
SetClipboardData( Block );
m_bSelected = FALSE;
} else {
CMemText Blck2; ActionCopyLine( Blck2 );
ActionDeleteLine();
Block.AppendText( Blck2 );
SetClipboardData( Block );
}
} else ActionWrongOperation(! bMacro);
}
void CCedtView::EventCommandCopyAppend(BOOL bMacro)
{
CMemText Block; GetClipboardData( Block );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -