⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cedtvieweditadv.cpp

📁 Crimson编辑器的英文版,完成从韩文版变成英文版的移植,并且附带可执行文件和注册表文件,无需原先的安装包,是改写编辑器的最理想选择.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	IndexToPosition( nAncX, nAncY, m_nAnchorPosX, m_nAnchorPosY );
}

void CCedtView::ActionConvertSpacesToTabs()
{
	INT nIdxX, nIdxY; PositionToIndex( m_nCaretPosX, m_nCaretPosY, nIdxX, nIdxY );
	INT nAncX, nAncY; PositionToIndex( m_nAnchorPosX, m_nAnchorPosY, nAncX, nAncY );

	ConvertSpacesToTabsDocument();

	IndexToPosition( nIdxX, nIdxY, m_nCaretPosX, m_nCaretPosY );
	IndexToPosition( nAncX, nAncY, m_nAnchorPosX, m_nAnchorPosY );
}

void CCedtView::ActionLeadingSpacesToTabs()
{
	INT nIdxX, nIdxY; PositionToIndex( m_nCaretPosX, m_nCaretPosY, nIdxX, nIdxY );
	INT nAncX, nAncY; PositionToIndex( m_nAnchorPosX, m_nAnchorPosY, nAncX, nAncY );

	LeadingSpacesToTabsDocument();

	IndexToPosition( nIdxX, nIdxY, m_nCaretPosX, m_nCaretPosY );
	IndexToPosition( nAncX, nAncY, m_nAnchorPosX, m_nAnchorPosY );
}

void CCedtView::ActionRemoveTrailingSpaces()
{
	INT nIdxX, nIdxY; PositionToIndex( m_nCaretPosX, m_nCaretPosY, nIdxX, nIdxY );
	INT nAncX, nAncY; PositionToIndex( m_nAnchorPosX, m_nAnchorPosY, nAncX, nAncY );

	DeleteTrailingSpacesDocument();

	IndexToPosition( nIdxX, nIdxY, m_nCaretPosX, m_nCaretPosY );
	IndexToPosition( nAncX, nAncY, m_nAnchorPosX, m_nAnchorPosY );
}


////////////////////////////////////////////////
// BASIC EDITING FUNCTIONS
void CCedtView::CopyToLineSelection(CMemText & rBlock, INT nBegX, INT nBegY, INT nEndX, INT nEndY)
{
	CCedtDoc * pDoc = (CCedtDoc *)GetDocument();
	pDoc->CopyToBlock(rBlock, nBegX, nBegY, nEndX, nEndY);
}

void CCedtView::InsertLineSelection(INT nBegX, INT nBegY, INT & nEndX, INT & nEndY, CMemText & rBlock)
{
	CCedtDoc * pDoc = (CCedtDoc *)GetDocument();
	pDoc->InsertBlock(nBegX, nBegY, nEndX, nEndY, rBlock); pDoc->InsertScreenText(nBegY, nEndY-nBegY);

	pDoc->AnalyzeText(nBegY, nEndY-nBegY+1);
	pDoc->FormatScreenText(nBegY, nEndY-nBegY+1);
}

void CCedtView::DeleteLineSelection(INT nBegX, INT nBegY, INT nEndX, INT nEndY)
{
	CCedtDoc * pDoc = (CCedtDoc *)GetDocument();
	pDoc->DeleteBlock(nBegX, nBegY, nEndX, nEndY); pDoc->RemoveScreenText(nBegY, nEndY-nBegY);

	pDoc->AnalyzeText(nBegY, 1);
	pDoc->FormatScreenText(nBegY, 1);
}

void CCedtView::ArrangeLineSelection(INT & nBegX, INT & nBegY, INT & nEndX, INT & nEndY)
{
	if( nBegX != 0 ) nBegX = 0;
	if( nEndX != 0 ) {
		if( nEndY == GetLastIdxY() ) {
			CAnalyzedString & rLine = GetLineFromIdxY( nEndY );
			nEndX = GetLastIdxX( rLine );
		} else { nEndY = nEndY + 1; nEndX = 0; }
	}
}

void CCedtView::IndentLineSelection(INT nBegX, INT nBegY, INT nEndX, INT nEndY)
{
	CCedtDoc * pDoc = (CCedtDoc *)GetDocument();
	pDoc->IndentBlock(nBegX, nBegY, nEndX, nEndY, m_nTabSize, m_bUseSpacesInPlaceOfTab);

	pDoc->AnalyzeText(nBegY, nEndY-nBegY+1);
	pDoc->FormatScreenText(nBegY, nEndY-nBegY+1);
}

void CCedtView::UnindentLineSelection(INT nBegX, INT nBegY, INT nEndX, INT nEndY)
{
	CCedtDoc * pDoc = (CCedtDoc *)GetDocument();
	pDoc->UnindentBlock(nBegX, nBegY, nEndX, nEndY, m_nTabSize);

	pDoc->AnalyzeText(nBegY, nEndY-nBegY+1);
	pDoc->FormatScreenText(nBegY, nEndY-nBegY+1);
}

void CCedtView::MakeCommentLineSelection(INT nBegX, INT nBegY, INT nEndX, INT nEndY)
{
	CCedtDoc * pDoc = (CCedtDoc *)GetDocument();
	pDoc->MakeCommentBlock(nBegX, nBegY, nEndX, nEndY);

	pDoc->AnalyzeText(nBegY, nEndY-nBegY+1);
	pDoc->FormatScreenText(nBegY, nEndY-nBegY+1);
}

void CCedtView::ReleaseCommentLineSelection(INT nBegX, INT nBegY, INT nEndX, INT nEndY)
{
	CCedtDoc * pDoc = (CCedtDoc *)GetDocument();
	pDoc->ReleaseCommentBlock(nBegX, nBegY, nEndX, nEndY);

	pDoc->AnalyzeText(nBegY, nEndY-nBegY+1);
	pDoc->FormatScreenText(nBegY, nEndY-nBegY+1);
}

void CCedtView::CopyToColumnSelection(CMemText & rBlock, INT nBegX, INT nBegY, INT nEndX, INT nEndY)
{
	rBlock.RemoveAll(); INT nLineHeight = GetLineHeight();

	for(INT nPosY = nBegY; nPosY <= nEndY; nPosY += nLineHeight ) {
		rBlock.AddTail(""); CString & rString = rBlock.GetTail();
		CFormatedString & rLine = GetLineFromPosY( nPosY );
		INT nIdxY = GetIdxYFromPosY( nPosY ), nLstX = GetLastPosX( rLine );

		if( nLstX > nEndX ) {
			INT nIdxX1 = GetIdxXFromPosX( rLine, nBegX, TRUE );
			INT nIdxX2 = GetIdxXFromPosX( rLine, nEndX, TRUE );

			FORMATEDWORDINFO & rWord1 = GetWordFromIdxX( rLine, nIdxX1 );
			FORMATEDWORDINFO & rWord2 = GetWordFromIdxX( rLine, nIdxX2 );

			BOOL bHalf1 = FALSE, bHalf2 = FALSE;
			if( rWord1.m_cType == WT_DBCHAR && rWord1.m_nPosition < nBegX ) bHalf1 = TRUE;
			if( rWord2.m_cType == WT_DBCHAR && rWord2.m_nPosition < nEndX ) bHalf2 = TRUE;

			if( bHalf1 && bHalf2 ) {
				CopyToString(rString, nIdxX1 + 2, nIdxY, nIdxX2 - nIdxX1 - 2);
				rString = CString(" ") + rString + CString(" ");
			} else if( bHalf1 ) {
				CopyToString(rString, nIdxX1 + 2, nIdxY, nIdxX2 - nIdxX1 - 2);
				rString = CString(" ") + rString;
			} else if( bHalf2 ) {
				CopyToString(rString, nIdxX1, nIdxY, nIdxX2 - nIdxX1);
				rString = rString + CString(" ");
			} else {
				CopyToString(rString, nIdxX1, nIdxY, nIdxX2 - nIdxX1);
			}
		} else if( nLstX > nBegX ) {
			INT nIdxX1 = GetIdxXFromPosX( rLine, nBegX, TRUE );
			INT nIdxX2 = GetIdxXFromPosX( rLine, nLstX, TRUE );

			FORMATEDWORDINFO & rWord = GetWordFromIdxX( rLine, nIdxX1 );
			BOOL bHalf = ( rWord.m_cType == WT_DBCHAR && rWord.m_nPosition < nBegX );

			if( bHalf ) {
				CopyToString( rString, nIdxX1 + 2, nIdxY, nIdxX2 - nIdxX1 - 2 );
				rString = CString(" ") + rString;
			} else {
				CopyToString( rString, nIdxX1, nIdxY, nIdxX2 - nIdxX1 );
			}
		}
	}
}

void CCedtView::InsertColumnSelection(INT nBegX, INT nBegY, INT & nEndX, INT & nEndY, CMemText & rBlock)
{
	INT nLineHeight = GetLineHeight(), nAveCharWidth = GetAveCharWidth();
	INT nLastPosY = GetLastPosY();

	rBlock.MakeEqualLength();
	INT nCount = rBlock.GetCount(), nMaxLen = rBlock.GetMaxLength();

	nEndX = nBegX + nMaxLen * nAveCharWidth;
	nEndY = nBegY + (nCount - 1) * nLineHeight;

	POSITION pos = rBlock.GetHeadPosition();

	for( INT nPosY = nBegY; nPosY <= nEndY; nPosY += nLineHeight ) {
		if( nPosY > nLastPosY ) { // append new empty line at the end of the document
			INT nPrevIdxY = GetIdxYFromPosY( nPosY - nLineHeight );
			CFormatedString & rPrevLine = GetLineFromPosY( nPosY - nLineHeight );
			SplitLine( GetLastIdxX(rPrevLine), nPrevIdxY );
		}

		CFormatedString & rLine = GetLineFromPosY( nPosY );
		INT nIdxY = GetIdxYFromPosY( nPosY ), nLstX = GetLastPosX( rLine );

		CString & rString = rBlock.GetNext( pos );
		INT nLength = rString.GetLength();

		if( nLstX < nBegX ) { // append blank spaces
			INT nIdxX = GetIdxXFromPosX( rLine, nLstX, TRUE );
			InsertString( nIdxX, nIdxY, CString( ' ', (nBegX - nLstX) / nAveCharWidth ) );
		} else { // check if double byte character need to be splitted
			INT nIdxX = GetIdxXFromPosX( rLine, nBegX, TRUE );
			FORMATEDWORDINFO & rWord = GetWordFromIdxX( rLine, nIdxX );
			if ( rWord.m_cType == WT_DBCHAR && rWord.m_nPosition < nBegX ) {
				DeleteString( nIdxX, nIdxY, 2 );
				InsertString( nIdxX, nIdxY, "  " );
			}
		}

		// now insert text block
		INT nIdxX = GetIdxXFromPosX( rLine, nBegX, TRUE );
		InsertString( nIdxX, nIdxY, rString );
	}
}

void CCedtView::DeleteColumnSelection(INT nBegX, INT nBegY, INT nEndX, INT nEndY)
{
	INT nLineHeight = GetLineHeight();

	for(INT nPosY = nBegY; nPosY <= nEndY; nPosY += nLineHeight ) {
		CFormatedString & rLine = GetLineFromPosY( nPosY );
		INT nIdxY = GetIdxYFromPosY( nPosY ), nLstX = GetLastPosX( rLine );

		if( nLstX > nEndX ) {
			INT nIdxX1 = GetIdxXFromPosX( rLine, nBegX, TRUE );
			INT nIdxX2 = GetIdxXFromPosX( rLine, nEndX, TRUE );

			FORMATEDWORDINFO & rWord1 = GetWordFromIdxX( rLine, nIdxX1 );
			FORMATEDWORDINFO & rWord2 = GetWordFromIdxX( rLine, nIdxX2 );

			BOOL bHalf1 = FALSE, bHalf2 = FALSE;
			if( rWord1.m_cType == WT_DBCHAR && rWord1.m_nPosition < nBegX ) bHalf1 = TRUE;
			if( rWord2.m_cType == WT_DBCHAR && rWord2.m_nPosition < nEndX ) bHalf2 = TRUE;

			if( bHalf1 && bHalf2 ) {
				DeleteString(nIdxX1, nIdxY, nIdxX2 - nIdxX1 + 2);
				InsertString(nIdxX1, nIdxY, "  ");
			} else if( bHalf1 ) {
				DeleteString(nIdxX1, nIdxY, nIdxX2 - nIdxX1);
				InsertChar(nIdxX1, nIdxY, ' ');
			} else if( bHalf2 ) {
				DeleteString(nIdxX1, nIdxY, nIdxX2 - nIdxX1 + 2);
				InsertChar(nIdxX1, nIdxY, ' ');
			} else {
				DeleteString(nIdxX1, nIdxY, nIdxX2 - nIdxX1);
			}
		} else if( nLstX > nBegX ) {
			INT nIdxX1 = GetIdxXFromPosX( rLine, nBegX, TRUE );
			INT nIdxX2 = GetIdxXFromPosX( rLine, nLstX, TRUE );

			FORMATEDWORDINFO & rWord = GetWordFromIdxX( rLine, nIdxX1 );
			BOOL bHalf = ( rWord.m_cType == WT_DBCHAR && rWord.m_nPosition < nBegX );

			if( bHalf ) {
				DeleteString(nIdxX1, nIdxY, nIdxX2 - nIdxX1);
				InsertChar(nIdxX1, nIdxY, ' ');
			} else {
				DeleteString(nIdxX1, nIdxY, nIdxX2 - nIdxX1);
			}
		}
	}
}

void CCedtView::ConvertTabsToSpacesDocument()
{
	CCedtDoc * pDoc = (CCedtDoc *)GetDocument();
	pDoc->ConvertTabsToSpacesDocument();

	pDoc->AnalyzeText();
	pDoc->FormatScreenText();
}

void CCedtView::ConvertSpacesToTabsDocument()
{
	CCedtDoc * pDoc = (CCedtDoc *)GetDocument();
	pDoc->ConvertSpacesToTabsDocument();

	pDoc->AnalyzeText();
	pDoc->FormatScreenText();
}

void CCedtView::LeadingSpacesToTabsDocument()
{
	CCedtDoc * pDoc = (CCedtDoc *)GetDocument();
	pDoc->LeadingSpacesToTabsDocument();

	pDoc->AnalyzeText();
	pDoc->FormatScreenText();
}

void CCedtView::DeleteTrailingSpacesDocument()
{
	CCedtDoc * pDoc = (CCedtDoc *)GetDocument();
	pDoc->DeleteTrailingSpacesDocument();

	pDoc->AnalyzeText();
	pDoc->FormatScreenText();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -