📄 cedtviewdraw.cpp
字号:
GetSelectedPosition( nBegX, nBegY, nEndX, nEndY );
RECT rectInvert;
INT nParaCount = 0, nLineCount = 0;
// SHORT siLineSplitIndex;
INT nCurY, nPosY; BOOL bLineVisible;
POSITION pos = m_clsFormatedScreenText.GetHeadPosition();
while( pos ) {
CFormatedString & rLine = m_clsFormatedScreenText.GetNext( pos );
// siLineSplitIndex = rLine.m_siLineSplitIndex;
nPosY = nLineCount * nLineHeight - m_nScrollPosY;
bLineVisible = (nPosY >= -nLineHeight) && (nPosY <= rect.bottom);
if( bLineVisible ) {
nCurY = nLineCount * nLineHeight;
if( nCurY >= nBegY && nCurY <= nEndY ) { // in block
rectInvert.top = nPosY;
rectInvert.bottom = nPosY + nCharHeight;
if( m_bColumnMode ) {
rectInvert.left = nBegX - m_nScrollPosX + nLeftMargin;
if( nBegX == nEndX && nCurY != m_nCaretPosY ) {
INT nCaretWidth = 25 * nAveCharWidth / 100; // default caret width
rectInvert.right = rectInvert.left + nCaretWidth;
} else rectInvert.right = nEndX - m_nScrollPosX + nLeftMargin;
} else {
if( nCurY == nBegY && nCurY == nEndY ) {
rectInvert.left = nBegX - m_nScrollPosX + nLeftMargin;
rectInvert.right = nEndX - m_nScrollPosX + nLeftMargin;
} else if( nCurY == nBegY ) {
rectInvert.left = nBegX - m_nScrollPosX + nLeftMargin;
rectInvert.right = GetLastPosX(rLine) - m_nScrollPosX + nLeftMargin + nAveCharWidth;
} else if( nCurY == nEndY ) {
rectInvert.left = GetFirstPosX(rLine) - m_nScrollPosX + nLeftMargin;
rectInvert.right = nEndX - m_nScrollPosX + nLeftMargin;
} else {
rectInvert.left = GetFirstPosX(rLine) - m_nScrollPosX + nLeftMargin;
rectInvert.right = GetLastPosX(rLine) - m_nScrollPosX + nLeftMargin + nAveCharWidth;
}
}
if( rectInvert.top < rect.top ) rectInvert.top = rect.top;
if( rectInvert.bottom > rect.bottom ) rectInvert.bottom = rect.bottom;
if( rectInvert.left < rect.left ) rectInvert.left = rect.left;
if( rectInvert.right > rect.right ) rectInvert.right = rect.right;
m_dcScreen.InvertRect( & rectInvert );
}
}
nLineCount++;
// if( siLineSplitIndex == 0 ) nParaCount++;
}
}
void CCedtView::DrawPrintPageOutline(CDC * pDC, RECT rectDraw, INT nCurPage)
{
CRect rect( rectDraw );
INT nLineHeight = GetLineHeight( pDC );
INT nPosX, nPosY; CSize size;
CPen pen( PS_SOLID, 1, RGB(0, 0, 0) );
CPen * pPenOld = pDC->SelectObject( & pen );
pDC->SetTextColor( RGB(0, 0, 0) );
if( m_bPrintHeader ) {
nPosY = - rect.top;
nPosX = rect.left;
pDC->TextOut(nPosX, nPosY, m_szHeaderString[0]);
size = pDC->GetTextExtent(m_szHeaderString[1]);
nPosX = rect.left + (rect.Width() - size.cx) / 2;
pDC->TextOut(nPosX, nPosY, m_szHeaderString[1]);
size = pDC->GetTextExtent(m_szHeaderString[2]);
nPosX = rect.right - size.cx;
pDC->TextOut(nPosX, nPosY, m_szHeaderString[2]);
nPosY = - rect.top - 4 * nLineHeight / 3;
pDC->MoveTo(rect.left, nPosY);
pDC->LineTo(rect.right, nPosY);
}
if( m_bPrintFooter ) {
nPosY = - rect.bottom + 4 * nLineHeight / 3;
pDC->MoveTo(rect.left, nPosY);
pDC->LineTo(rect.right, nPosY);
nPosY = - rect.bottom + nLineHeight;
nPosX = rect.left;
pDC->TextOut(nPosX, nPosY, m_szFooterString[0]);
size = pDC->GetTextExtent(m_szFooterString[1]);
nPosX = rect.left + (rect.Width() - size.cx) / 2;
pDC->TextOut(nPosX, nPosY, m_szFooterString[1]);
size = pDC->GetTextExtent(m_szFooterString[2]);
nPosX = rect.right - size.cx;
pDC->TextOut(nPosX, nPosY, m_szFooterString[2]);
}
pDC->SelectObject( pPenOld );
}
void CCedtView::DrawPrintPageBackgroundAndText(CDC * pDC, RECT rectDraw, INT nCurPage)
{
CRect rect( rectDraw );
INT nCharHeight = GetCharHeight(pDC); INT nLineHeight = GetLineHeight(pDC);
INT nLeftMargin = GetLeftMargin(pDC); INT nAveCharWidth = GetAveCharWidth(pDC);
INT nLinesPerPage = rect.Height() / nLineHeight;
if( m_bPrintHeader ) { nLinesPerPage = nLinesPerPage - 2; rect.top = rect.top + 2 * nLineHeight; }
if( m_bPrintFooter ) { nLinesPerPage = nLinesPerPage - 2; rect.bottom = rect.bottom - 2 * nLineHeight; }
INT nScrollPosY = (nCurPage - 1) * nLinesPerPage * nLineHeight;
INT nNumWidth = GetNumberWidth(pDC);
INT nSpaceWidth = GetSpaceWidth(pDC);
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 = m_nFormatedPrintTextStartIdxY, nLineCount = 0; SHORT sWordCount;
INT nParaMax = GetLastIdxY(), nLineMax = GetLastPosY() / nLineHeight;
SHORT sInfoFlags, sLineSplitIndex; UCHAR cType, cType2, cRange; INT nPosition, nWidth;
INT nPosX = 0, nPosY = 0; BOOL bLineVisible, bWordVisible;
POSITION pos = m_clsFormatedPrintText.GetHeadPosition();
while( pos ) {
CFormatedString & rLine = m_clsFormatedPrintText.GetNext( pos );
sInfoFlags = rLine.m_sInfoFlags; sLineSplitIndex = rLine.m_sLineSplitIndex;
nPosY = nLineCount * nLineHeight - nScrollPosY;
bLineVisible = (nPosY >= 0) && (nPosY <= rect.Height() - nLineHeight);
if( sLineSplitIndex == 0 ) bLineComment = FALSE;
if( sLineSplitIndex == 0 && ! bMultiLineStringConstant ) bQuotation1 = bQuotation2 = bQuotation3 = FALSE;
if( bLineVisible ) {
// draw line number
if( m_bPrintLineNumbers && sLineSplitIndex == 0 ) {
szLineNumber.Format("%d:", nParaCount+1);
size = pDC->GetTextExtent(szLineNumber);
nPosX = nLeftMargin - size.cx - nNumWidth / 1;
pDC->SetTextColor( RGB(0, 0, 0) );
pDC->TextOut(rect.left+nPosX, -rect.top-nPosY, szLineNumber);
}
// 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;
if( cType == WT_RETURN || cType == WT_LINEFEED ) nWidth = rect.right - rect.left - nPosX;
bWordVisible = nPosX + nWidth >= nLeftMargin && nPosX <= rect.right;
cType2 = _CheckType(cType, cRange, bQuotation1, bQuotation2, bQuotation3, bLineComment, bBlockComment, bHighlight, bShadow, bRange1, bRange2);
if( m_bPrintSyntaxHighlight && bWordVisible && (bRange1 || cType == WT_RANGE1END) && m_crBkgrColor[0] != m_crBkgrColor[3] ) {
if( sWordCount == 0 && nPosition != 0 ) pDC->FillSolidRect(rect.left+nLeftMargin, -(rect.top+nPosY+nCharHeight)-(nLineHeight-nCharHeight)/2, nPosX-nLeftMargin, nLineHeight, m_crBkgrColor[0x03]);
pDC->FillSolidRect(rect.left+nPosX, -(rect.top+nPosY+nCharHeight)-(nLineHeight-nCharHeight)/2, nWidth, nLineHeight, m_crBkgrColor[0x03]);
}
if( m_bPrintSyntaxHighlight && bWordVisible && (bRange2 || cType == WT_RANGE2END) && ! bRange1 && m_crBkgrColor[0] != m_crBkgrColor[4] ) {
if( sWordCount == 0 && nPosition != 0 ) pDC->FillSolidRect(rect.left+nLeftMargin, -(rect.top+nPosY+nCharHeight)-(nLineHeight-nCharHeight)/2, nPosX-nLeftMargin, nLineHeight, m_crBkgrColor[0x04]);
pDC->FillSolidRect(rect.left+nPosX, -(rect.top+nPosY+nCharHeight)-(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;
if( cType == WT_RETURN || cType == WT_LINEFEED ) nWidth = rect.right - rect.left - 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_bPrintSyntaxHighlight ) pDC->SetTextColor(RGB(0, 0, 0));
else if( bLineComment || bBlockComment ) pDC->SetTextColor(m_crTextColor[WT_LINECOMMENT]);
else if( bHighlight ) pDC->SetTextColor(m_crTextColor[WT_HIGHLIGHTON]);
else if( bShadow ) pDC->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 pDC->SetTextColor(m_crTextColor[WT_QUOTATION1]);
} else if( _IS_BET(WT_KEYWORD0, cType, WT_KEYWORD9) && cRange != RT_GLOBAL ) {
if( _CheckRange(bRange1, bRange2, cRange) ) pDC->SetTextColor(m_crTextColor[cType2]);
else pDC->SetTextColor(m_crTextColor[WT_WORD]);
} else pDC->SetTextColor(m_crTextColor[cType2]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -