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

📄 cedtviewscroll.cpp

📁 Crimson编辑器的英文版,完成从韩文版变成英文版的移植,并且附带可执行文件和注册表文件,无需原先的安装包,是改写编辑器的最理想选择.
💻 CPP
字号:
#include "stdafx.h"
#include "cedtHeader.h"


void CCedtView::SetScrollPosY(INT nPosY)
{
	INT nLineHeight = GetLineHeight();
	INT nLastPosY = GetLastPosY();

	if( nPosY > nLastPosY ) m_nScrollPosY = nLastPosY;
	else if( nPosY > 0 ) m_nScrollPosY = (nPosY / nLineHeight) * nLineHeight;
	else m_nScrollPosY = 0;
}

void CCedtView::SetScrollPosX(INT nPosX)
{
	if( nPosX > 0 ) m_nScrollPosX = nPosX;
	else m_nScrollPosX = 0;
}

void CCedtView::SetScrollPosSyncAllPanes(INT nPosX, INT nPosY)
{
	CChildFrame * pChild = (CChildFrame *)GetParentFrame(); ASSERT( pChild );
	pChild->SetScrollPosSyncAllPanes(this, nPosX, nPosY);
}

void CCedtView::SetScrollPosToMakeCaretVisible()
{
	RECT rect; GetClientRect( & rect );
	INT nLeftMargin = GetLeftMargin();	INT nMaxCharWidth = GetMaxCharWidth();
	INT nLineHeight = GetLineHeight();	INT nLinesPerPage = GetLinesPerPage();

	INT nIncrementX = 16 * GetAveCharWidth();
	INT nPosX = m_nScrollPosX;			INT nPosY = m_nScrollPosY;

	if( m_nCaretPosX < m_nScrollPosX ) nPosX = m_nCaretPosX - nIncrementX;
	if( m_nCaretPosX > m_nScrollPosX - nLeftMargin + rect.right - nMaxCharWidth ) nPosX = m_nCaretPosX + nLeftMargin - rect.right + nIncrementX;
	if( m_nCaretPosY < m_nScrollPosY ) nPosY = m_nCaretPosY;
	if( m_nCaretPosY > m_nScrollPosY + (nLinesPerPage - 1) * nLineHeight ) nPosY = m_nCaretPosY - (nLinesPerPage - 1) * nLineHeight;

	SetScrollPosSyncAllPanes(nPosX, nPosY);
}

void CCedtView::SetScrollPosToMakeAutoScroll()
{
	RECT rect; GetClientRect( & rect );
	INT nLeftMargin = GetLeftMargin();	INT nMaxCharWidth = GetMaxCharWidth();
	INT nLineHeight = GetLineHeight();	INT nLinesPerPage = GetLinesPerPage();

	INT nPosX = m_nScrollPosX;			INT nPosY = m_nScrollPosY;

	if( m_nCaretPosX < m_nScrollPosX ) nPosX = m_nCaretPosX;
	if( m_nCaretPosX > m_nScrollPosX - nLeftMargin + rect.right - nMaxCharWidth ) nPosX = m_nCaretPosX + nLeftMargin - rect.right + nMaxCharWidth;
	if( m_nCaretPosY < m_nScrollPosY ) nPosY = m_nCaretPosY;;
	if( m_nCaretPosY > m_nScrollPosY + (nLinesPerPage - 1) * nLineHeight ) nPosY = m_nCaretPosY - (nLinesPerPage - 1) * nLineHeight;

	SetScrollPosSyncAllPanes(nPosX, nPosY);
}

void CCedtView::SetScrollPosToMakeDragScroll()
{
	RECT rect; GetClientRect( & rect );
	INT nLeftMargin = GetLeftMargin();	INT nMaxCharWidth = GetMaxCharWidth();
	INT nLineHeight = GetLineHeight();	INT nLinesPerPage = GetLinesPerPage();

	INT nSkip = (rect.bottom % nLineHeight < nLineHeight / 2) ? 2 : 1;
	INT nPosX = m_nScrollPosX;			INT nPosY = m_nScrollPosY;

	if( m_nDragPosX < m_nScrollPosX ) nPosX = m_nDragPosX;
	if( m_nDragPosX > m_nScrollPosX - nLeftMargin + rect.right - nMaxCharWidth ) nPosX = m_nDragPosX + nLeftMargin - rect.right + nMaxCharWidth;
	if( m_nDragPosY < m_nScrollPosY + nLineHeight ) nPosY = m_nDragPosY - nLineHeight;
	if( m_nDragPosY > m_nScrollPosY + (nLinesPerPage - nSkip) * nLineHeight ) nPosY = m_nDragPosY - (nLinesPerPage - nSkip) * nLineHeight;

	SetScrollPosSyncAllPanes(nPosX, nPosY);
}

void CCedtView::SetScrollPosToMakeCaretTop()
{
	SetScrollPosSyncAllPanes( m_nScrollPosX, m_nCaretPosY );
	SetScrollPosToMakeCaretVisible();
}

void CCedtView::SetScrollPosToMakeCaretBottom()
{
	SetScrollPosSyncAllPanes( m_nScrollPosX, m_nCaretPosY - (GetLinesPerPage() - 1) * GetLineHeight() );
	SetScrollPosToMakeCaretVisible();
}

void CCedtView::SetScrollPosToMakeCaretCenter()
{
//	RECT rect; GetClientRect( & rect );
	SetScrollPosSyncAllPanes( m_nScrollPosX, m_nCaretPosY - (GetLinesPerPage() - 1) / 2 * GetLineHeight() );
	SetScrollPosToMakeCaretVisible();
}

⌨️ 快捷键说明

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