📄 cedtviewdraw.cpp
字号:
#include "stdafx.h"
#include "cedtHeader.h"
static BOOL _CheckRange(BOOL bRange1, BOOL bRange2, UCHAR cRange)
{
switch( cRange ) {
case RT_GLOBAL: return TRUE;
case RT_RANGE1: return bRange1;
case RT_RANGE2: return bRange2;
case RT_NR1AR2: return (! bRange1 && bRange2);
case RT_NRNGE1: return (! bRange1);
case RT_NRNGE2: return (! bRange2);
case RT_R1ORR2: return (bRange1 || bRange2);
default: return FALSE;
}
}
static UCHAR _CheckType(UCHAR cType, UCHAR cRange, BOOL & bQuotation1, BOOL & bQuotation2, BOOL & bQuotation3, BOOL & bLineComment, BOOL & bBlockComment, BOOL & bHighlight, BOOL & bShadow, BOOL & bRange1, BOOL & bRange2)
{
switch( cType ) {
case WT_COMMENTON: if( ! bQuotation1 && ! bQuotation2 && ! bQuotation3 && ! bLineComment && _CheckRange(bRange1, bRange2, cRange) ) { bBlockComment = TRUE; return WT_LINECOMMENT; } else return WT_DELIMITER;
case WT_COMMENTOFF: if( ! bQuotation1 && ! bQuotation2 && ! bQuotation3 && bBlockComment && _CheckRange(bRange1, bRange2, cRange) ) { bBlockComment = FALSE; return WT_LINECOMMENT; } else return WT_DELIMITER;
case WT_LINECOMMENT: if( ! bQuotation1 && ! bQuotation2 && ! bQuotation3 && ! bBlockComment && _CheckRange(bRange1, bRange2, cRange) ) { bLineComment = TRUE; return WT_LINECOMMENT; } else return WT_DELIMITER;
case WT_QUOTATION1: if( ! bQuotation2 && ! bQuotation3 && ! bLineComment && ! bBlockComment && _CheckRange(bRange1, bRange2, cRange) ) { bQuotation1 = ! bQuotation1; return WT_QUOTATION1; } else return WT_DELIMITER;
case WT_QUOTATION2: if( ! bQuotation1 && ! bQuotation3 && ! bLineComment && ! bBlockComment && _CheckRange(bRange1, bRange2, cRange) ) { bQuotation2 = ! bQuotation2; return WT_QUOTATION1; } else return WT_DELIMITER;
case WT_QUOTATION3: if( ! bQuotation1 && ! bQuotation2 && ! bLineComment && ! bBlockComment && _CheckRange(bRange1, bRange2, cRange) ) { bQuotation3 = ! bQuotation3; return WT_QUOTATION1; } else return WT_DELIMITER;
case WT_SHADOWON: if( ! bQuotation1 && ! bQuotation2 && ! bQuotation3 && ! bLineComment && ! bBlockComment ) bShadow = TRUE; return WT_SHADOWON;
case WT_SHADOWOFF: if( ! bQuotation1 && ! bQuotation2 && ! bQuotation3 && ! bLineComment && ! bBlockComment ) bShadow = FALSE; return WT_SHADOWON;
case WT_HIGHLIGHTON: if( ! bQuotation1 && ! bQuotation2 && ! bQuotation3 && ! bLineComment && ! bBlockComment ) bHighlight = TRUE; return WT_HIGHLIGHTON;
case WT_HIGHLIGHTOFF: if( ! bQuotation1 && ! bQuotation2 && ! bQuotation3 && ! bLineComment && ! bBlockComment ) bHighlight = FALSE; return WT_HIGHLIGHTON;
case WT_RANGE1BEG: if( ! bQuotation1 && ! bQuotation2 && ! bQuotation3 && ! bLineComment && ! bBlockComment ) bRange1 = TRUE; return WT_DELIMITER;
case WT_RANGE1END: if( ! bQuotation1 && ! bQuotation2 && ! bQuotation3 && ! bLineComment && ! bBlockComment ) bRange1 = FALSE; return WT_DELIMITER;
case WT_RANGE2BEG: if( ! bQuotation1 && ! bQuotation2 && ! bQuotation3 && ! bLineComment && ! bBlockComment && ! bRange1 ) bRange2 = TRUE; return WT_DELIMITER;
case WT_RANGE2END: if( ! bQuotation1 && ! bQuotation2 && ! bQuotation3 && ! bLineComment && ! bBlockComment && ! bRange1 ) bRange2 = FALSE; return WT_DELIMITER;
default: return cType;
}
}
void CCedtView::DrawScreenBackgroundAndText()
{
CRect rect; GetClientRect( & rect );
INT nCharHeight = GetCharHeight(); INT nLineHeight = GetLineHeight();
INT nLeftMargin = GetLeftMargin(); INT nAveCharWidth = GetAveCharWidth();
INT nNumWidth = GetNumberWidth();
INT nSpaceWidth = GetSpaceWidth();
CSize size; CString szLineNumber;
BOOL bMultiLineStringConstant = MultiLineStringConstant();
BOOL bVariableHighlightInString = VariableHighlightInString();
BOOL bQuotation1 = FALSE, bQuotation2 = FALSE, bQuotation3 = FALSE, bLineComment = FALSE, bBlockComment = FALSE;
BOOL bHighlight = FALSE, bShadow = FALSE, bRange1 = FALSE, bRange2 = FALSE;
BOOL bQuotation1Save, bQuotation2Save, bQuotation3Save, bLineCommentSave, bBlockCommentSave;
BOOL bHighlightSave, bShadowSave, bRange1Save, bRange2Save;
INT nParaCount = 0, nLineCount = 0; SHORT sWordCount, sSpaceCount;
INT nParaMax = GetLastIdxY(), nLineMax = GetLastPosY() / nLineHeight;
SHORT sInfoFlags, sLineSplitIndex; UCHAR cType, cType2, cRange; INT nPosition, nWidth;
INT nPosX = 0, nPosY = 0; BOOL bLineVisible, bWordVisible;
// fill background
m_dcScreen.SelectClipRgn( NULL, RGN_COPY );
if( m_bShowLineNumbers || m_bShowSelectionMargin ) {
m_dcScreen.FillSolidRect(0, 0, nLeftMargin-1, rect.bottom, m_crBkgrColor[1]);
m_dcScreen.FillSolidRect(nLeftMargin-1, 0, rect.right-nLeftMargin+1, rect.bottom, m_crBkgrColor[0]);
} else {
m_dcScreen.FillSolidRect(0, 0, rect.right, rect.bottom, m_crBkgrColor[0]);
}
POSITION pos = m_clsFormatedScreenText.GetHeadPosition();
while( pos ) {
CFormatedString & rLine = m_clsFormatedScreenText.GetNext( pos );
sInfoFlags = rLine.m_sInfoFlags; sLineSplitIndex = rLine.m_sLineSplitIndex;
nPosY = nLineCount * nLineHeight - m_nScrollPosY;
bLineVisible = (nPosY >= -nLineHeight) && (nPosY <= rect.Height());
if( sLineSplitIndex == 0 ) bLineComment = FALSE;
if( sLineSplitIndex == 0 && ! bMultiLineStringConstant ) bQuotation1 = bQuotation2 = bQuotation3 = FALSE;
if( bLineVisible ) {
// draw line number
if( m_bShowLineNumbers && sLineSplitIndex == 0 ) {
szLineNumber.Format("%d", nParaCount+1);
size = m_dcScreen.GetTextExtent(szLineNumber);
nPosX = nLeftMargin - size.cx - nNumWidth / 2;
m_dcScreen.SetTextColor( m_crTextColor[WT_LINEFEED] );
m_dcScreen.TextOut(nPosX, nPosY, szLineNumber);
}
// draw bookmark
if( (sInfoFlags & LT_HASBOOKMARK) && sLineSplitIndex == 0 ) {
if( m_bShowLineNumbers || m_bShowSelectionMargin ) {
DrawScreenBookmark(nLeftMargin-5*nNumWidth/2+1, nPosY+1, 2*nNumWidth-2, nCharHeight-2);
} else {
COLORREF clr = RGB(0, 128, 128) ^ m_crBkgrColor[0];
m_dcScreen.FillSolidRect(nLeftMargin, nPosY, rect.right-nLeftMargin, nCharHeight, clr);
}
}
// exclude left margin from drawing
m_dcScreen.ExcludeClipRect(0, nPosY, nLeftMargin, nPosY + nLineHeight);
// save status of before drawing background
bQuotation1Save = bQuotation1; bQuotation2Save = bQuotation2; bQuotation3Save = bQuotation3; bLineCommentSave = bLineComment; bBlockCommentSave = bBlockComment;
bHighlightSave = bHighlight; bShadowSave = bShadow; bRange1Save = bRange1; bRange2Save = bRange2;
// drawing background - the reason why we split from drawing background from drawing text is that
// when the font is italic drawing next background will erase part of previous text
for(sWordCount = 0; sWordCount < rLine.m_sWordCount; sWordCount++) {
FORMATEDWORDINFO & rWord = rLine.m_pWordInfo[sWordCount];
cType = rWord.m_cType; cRange = rWord.m_cRange;
nPosition = rWord.m_nPosition; nWidth = rWord.m_nWidth;
nPosX = nLeftMargin + nPosition - m_nScrollPosX;
if( cType == WT_RETURN || cType == WT_LINEFEED ) nWidth = rect.right - nPosX;
bWordVisible = nPosX + nWidth >= nLeftMargin && nPosX <= rect.right;
cType2 = _CheckType(cType, cRange, bQuotation1, bQuotation2, bQuotation3, bLineComment, bBlockComment, bHighlight, bShadow, bRange1, bRange2);
if( m_bSyntaxHighlight && bWordVisible && (bRange1 || cType == WT_RANGE1END) && m_crBkgrColor[0] != m_crBkgrColor[3] ) {
if( sWordCount == 0 && nPosition != 0 ) m_dcScreen.FillSolidRect(nLeftMargin, nPosY-(nLineHeight-nCharHeight)/2, nPosX-nLeftMargin, nLineHeight, m_crBkgrColor[0x03]);
m_dcScreen.FillSolidRect(nPosX, nPosY-(nLineHeight-nCharHeight)/2, nWidth, nLineHeight, m_crBkgrColor[0x03]);
}
if( m_bSyntaxHighlight && bWordVisible && (bRange2 || cType == WT_RANGE2END) && ! bRange1 && m_crBkgrColor[0] != m_crBkgrColor[4] ) {
if( sWordCount == 0 && nPosition != 0 ) m_dcScreen.FillSolidRect(nLeftMargin, nPosY-(nLineHeight-nCharHeight)/2, nPosX-nLeftMargin, nLineHeight, m_crBkgrColor[0x04]);
m_dcScreen.FillSolidRect(nPosX, nPosY-(nLineHeight-nCharHeight)/2, nWidth, nLineHeight, m_crBkgrColor[0x04]);
}
}
// restore status of before drawing text
bQuotation1 = bQuotation1Save; bQuotation2 = bQuotation2Save; bQuotation3 = bQuotation3Save; bLineComment = bLineCommentSave; bBlockComment = bBlockCommentSave;
bHighlight = bHighlightSave; bShadow = bShadowSave; bRange1 = bRange1Save; bRange2 = bRange2Save;
// drawing text
for(sWordCount = 0; sWordCount < rLine.m_sWordCount; sWordCount++) {
FORMATEDWORDINFO & rWord = rLine.m_pWordInfo[sWordCount];
cType = rWord.m_cType; cRange = rWord.m_cRange;
nPosition = rWord.m_nPosition; nWidth = rWord.m_nWidth;
nPosX = nLeftMargin + nPosition - m_nScrollPosX;
if( cType == WT_RETURN || cType == WT_LINEFEED ) nWidth = rect.right - nPosX;
bWordVisible = nPosX + nWidth >= nLeftMargin && nPosX <= rect.right;
cType2 = _CheckType(cType, cRange, bQuotation1, bQuotation2, bQuotation3, bLineComment, bBlockComment, bHighlight, bShadow, bRange1, bRange2);
if( bWordVisible && cType != WT_LINEFEED ) {
if( ! m_bSyntaxHighlight ) m_dcScreen.SetTextColor(m_crTextColor[WT_WORD]);
else if( bLineComment || bBlockComment ) m_dcScreen.SetTextColor(m_crTextColor[WT_LINECOMMENT]);
else if( bHighlight ) m_dcScreen.SetTextColor(m_crTextColor[WT_HIGHLIGHTON]);
else if( bShadow ) m_dcScreen.SetTextColor(m_crTextColor[WT_SHADOWON]);
else if( bQuotation1 || bQuotation2 || bQuotation3 ) {
if( bVariableHighlightInString && cType2 == WT_VARIABLE ) m_dcScreen.SetTextColor(m_crTextColor[WT_VARIABLE] / 2 + m_crTextColor[WT_QUOTATION1] / 2);
else m_dcScreen.SetTextColor(m_crTextColor[WT_QUOTATION1]);
} else if( _IS_BET(WT_KEYWORD0, cType, WT_KEYWORD9) && cRange != RT_GLOBAL ) {
if( _CheckRange(bRange1, bRange2, cRange) ) m_dcScreen.SetTextColor(m_crTextColor[cType2]);
else m_dcScreen.SetTextColor(m_crTextColor[WT_WORD]);
} else m_dcScreen.SetTextColor(m_crTextColor[cType2]);
if( m_bShowLineBreak && cType == WT_RETURN && nParaCount != nParaMax ) {
DrawScreenLineBreak(nPosX, nPosY, nSpaceWidth, nLineHeight);
} else if( m_bShowTabChars && cType == WT_TAB ) {
DrawScreenTabChar(nPosX, nPosY, nSpaceWidth, nLineHeight);
} else if( m_bShowSpaces && cType == WT_SPACE ) {
for(sSpaceCount = 0; sSpaceCount < rWord.m_sLength; sSpaceCount++) {
DrawScreenSpace(nPosX + sSpaceCount * nSpaceWidth, nPosY, nSpaceWidth, nLineHeight);
}
} else if( cType != WT_RETURN && cType != WT_TAB && cType != WT_SPACE ) {
// set font to italic
if( m_bItalicizeComment && (bLineComment || bBlockComment || cType2 == WT_LINECOMMENT) ) m_dcScreen.SelectObject( & m_fontScreenIt );
m_dcScreen.TextOut(nPosX, nPosY, (LPCTSTR)rLine + rWord.m_sIndex, rWord.m_sLength);
if( m_bEmboldenKeywords && ! bLineComment && ! bBlockComment && ! bShadow && ! bQuotation1 && ! bQuotation2 && ! bQuotation3
&& _IS_BET(WT_KEYWORD0, cType, WT_KEYWORD9) && _CheckRange(bRange1, bRange2, cRange) )
m_dcScreen.TextOut(nPosX+1, nPosY, (LPCTSTR)rLine + rWord.m_sIndex, rWord.m_sLength);
if( m_bLocalSpellCheck /* && ! bLineComment && ! bBlockComment && ! bQuotation1 && ! bQuotation2 */ && cType == WT_WRONGWORD )
DrawScreenUnderbar(nPosX, nPosY+nCharHeight-1, rWord.m_nWidth, 1);
// restore font from italic
if( m_bItalicizeComment && (bLineComment || bBlockComment || cType2 == WT_LINECOMMENT) ) m_dcScreen.SelectObject( & m_fontScreen );
}
}
}
} else if( sInfoFlags & LT_HASRANGE || sInfoFlags & LT_HASCOMMENT || sInfoFlags & LT_HASHIGHLIGHT || sInfoFlags & LT_HASQUOTATION ) {
for(sWordCount = 0; sWordCount < rLine.m_sWordCount; sWordCount++) {
FORMATEDWORDINFO & rWord = rLine.m_pWordInfo[sWordCount];
cType = rWord.m_cType; cRange = rWord.m_cRange;
if( _IS_BET(WT_RANGE1BEG, cType, WT_RANGE2END) ||
_IS_BET(WT_LINECOMMENT, cType, WT_COMMENTOFF) ||
_IS_BET(WT_SHADOWON, cType, WT_HIGHLIGHTOFF) ||
_IS_BET(WT_QUOTATION1, cType, WT_QUOTATION3) )
_CheckType(cType, cRange, bQuotation1, bQuotation2, bQuotation3, bLineComment, bBlockComment, bHighlight, bShadow, bRange1, bRange2);
}
}
nLineCount++;
if( sLineSplitIndex == 0 ) nParaCount++;
}
}
void CCedtView::InvertScreenSelected()
{
RECT rect; GetClientRect( & rect );
INT nCharHeight = GetCharHeight(); INT nLineHeight = GetLineHeight();
INT nLeftMargin = GetLeftMargin(); INT nAveCharWidth = GetAveCharWidth();
INT nBegX, nBegY, nEndX, nEndY;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -