📄 clayoutmgr_new.cpp
字号:
//@@@ 2002.09.22 YAZAKI
bool bGotoSEARCH_START = CheckColorMODE( nCOMMENTMODE, nCOMMENTEND, nPos, nLineLen, pLine, bDispSSTRING, bDispWSTRING );
if ( bGotoSEARCH_START )
goto SEARCH_START;
if( pLine[nPos] == TAB ){
// Sep. 23, 2002 genta せっかく作ったので関数を使う
nCharChars = GetActualTabSpace( nPosX );
if( nPosX + nCharChars > nMaxLineSize ){
//@@@ 2002.09.23 YAZAKI 最適化
if( bNeedChangeCOMMENTMODE ){
pLayout = pLayout->m_pNext;
pLayout->m_nTypePrev = nCOMMENTMODE_Prev;
(*pnExtInsLineNum)++; // 再描画してほしい行数+1
}
else {
pLayout = InsertLineNext( pLayout, CreateLayout(pCDocLine, nCurLine, nBgn, nPos - nBgn, nCOMMENTMODE_Prev, nIndent) );
}
nCOMMENTMODE_Prev = nCOMMENTMODE;
nBgn = nPos;
// 2004.03.28 Moca nPosXはインデント幅を含むように変更(TAB位置調整のため)
nPosX = nIndent = (this->*getIndentOffset)( pLayout );
pLayoutCalculated = pLayout;
if( ( nDelLogicalLineFrom == nCurLine && nDelLogicalColFrom < nPos ) ||
( nDelLogicalLineFrom < nCurLine )
){
(nModifyLayoutLinesNew)++;;
}
continue;
}
nPos++;
}else{
nCharChars = CMemory::MemCharNext( pLine, nLineLen, &pLine[nPos] ) - &pLine[nPos];
if( 0 == nCharChars ){
nCharChars = 1;
break; //@@@ 2002.04.16 MIK
}
if( nPosX + nCharChars > nMaxLineSize ){
if( nKinsokuType != KINSOKU_TYPE_KINSOKU_KUTO )
{
if( ! (m_bKinsokuRet && (nPos == nLineLen - nEol) && nEol) ) //改行文字をぶら下げる //@@@ 2002.04.14 MIK
{ //@@@ 2002.04.14 MIK
//@@@ 2002.09.23 YAZAKI 最適化
if( bNeedChangeCOMMENTMODE ){
pLayout = pLayout->m_pNext;
pLayout->m_nTypePrev = nCOMMENTMODE_Prev;
(*pnExtInsLineNum)++; // 再描画してほしい行数+1
}
else {
pLayout = InsertLineNext( pLayout, CreateLayout(pCDocLine, nCurLine, nBgn, nPos - nBgn, nCOMMENTMODE_Prev, nIndent) );
}
nCOMMENTMODE_Prev = nCOMMENTMODE;
nBgn = nPos;
// 2004.03.28 Moca nPosXはインデント幅を含むように変更(TAB位置調整のため)
nPosX = nIndent = (this->*getIndentOffset)( pLayout );
pLayoutCalculated = pLayout;
if( ( nDelLogicalLineFrom == nCurLine && nDelLogicalColFrom < nPos ) ||
( nDelLogicalLineFrom < nCurLine )
){
(nModifyLayoutLinesNew)++;;
}
continue;
}
}
}
nPos+= nCharChars;
}
nPosX += nCharChars;
}
if( nPos - nBgn > 0 ){
// 2002/03/13 novice
if( nCOMMENTMODE == COLORIDX_COMMENT ){ /* 行コメントである */
nCOMMENTMODE = COLORIDX_TEXT;
}
//@@@ 2002.09.23 YAZAKI 最適化
if( bNeedChangeCOMMENTMODE ){
pLayout = pLayout->m_pNext;
pLayout->m_nTypePrev = nCOMMENTMODE_Prev;
(*pnExtInsLineNum)++; // 再描画してほしい行数+1
}
else {
pLayout = InsertLineNext( pLayout, CreateLayout(pCDocLine, nCurLine, nBgn, nPos - nBgn, nCOMMENTMODE_Prev, nIndent) );
}
nCOMMENTMODE_Prev = nCOMMENTMODE;
if( ( nDelLogicalLineFrom == nCurLine && nDelLogicalColFrom < nPos ) ||
( nDelLogicalLineFrom < nCurLine )
){
(nModifyLayoutLinesNew)++;;
}
}
nLineNumWork++;
nCurLine++;
/* 目的の行数(nLineNum)に達したか、または通り過ぎた(=行数が増えた)か確認 */
//@@@ 2002.09.23 YAZAKI 最適化
if( nLineNumWork >= nLineNum ){
if( NULL != pLayout
&& NULL != pLayout->m_pNext
&& ( nCOMMENTMODE_Prev != pLayout->m_pNext->m_nTypePrev )
){
// COMMENTMODEが異なる行が増えましたので、次の行→次の行と更新していきます。
bNeedChangeCOMMENTMODE = true;
}else{
break; // while( NULL != pCDocLine ) 終了
}
}
// pLine = m_pcDocLineMgr->GetNextLinrStr( &nLineLen );
pCDocLine = pCDocLine->m_pNext;
// 2002/03/13 novice
if( nCOMMENTMODE_Prev == COLORIDX_COMMENT ){ /* 行コメントである */
nCOMMENTMODE_Prev = COLORIDX_TEXT;
}
nCOMMENTMODE = nCOMMENTMODE_Prev;
nCOMMENTEND = 0;
}
// 2004.03.28 Moca EOFだけの論理行の直前の行の色分けが確認?更新された
if( nCurLine == m_pcDocLineMgr->GetLineCount() ){
m_nLineTypeBot = nCOMMENTMODE_Prev;
}
// 1999.12.22 レイアウト情報がなくなる訳ではないので
// m_nPrevReferLine = 0;
// m_pLayoutPrevRefer = NULL;
// m_pLayoutCurrent = NULL;
return nModifyLayoutLinesNew;
}
bool CLayoutMgr::IsKinsokuHead( const char *pLine, int length )
{
const unsigned char *p;
if( length == 1 ) p = (const unsigned char *)m_pszKinsokuHead_1;
else if( length == 2 ) p = (const unsigned char *)m_pszKinsokuHead_2;
else return false;
if( ! p ) return false;
for( ; *p; p += length )
{
if( memcmp( pLine, p, length ) == 0 ) return true;
}
return false;
}
bool CLayoutMgr::IsKinsokuTail( const char *pLine, int length )
{
const unsigned char *p;
if( length == 1 ) p = (const unsigned char *)m_pszKinsokuTail_1;
else if( length == 2 ) p = (const unsigned char *)m_pszKinsokuTail_2;
else return false;
if( ! p ) return false;
for( ; *p; p += length )
{
if( memcmp( pLine, p, length ) == 0 ) return true;
}
return false;
}
bool CLayoutMgr::IsKutoTen( unsigned char c1, unsigned char c2 )
{
static const char *KUTOTEN_1 = "??,.";
static const char *KUTOTEN_2 = "。、,.";
unsigned const char *p;
if( c2 ) //全角
{
for( p = (const unsigned char *)KUTOTEN_2; *p; p += 2 )
{
if( *p == c1 && *(p + 1) == c2 ) return true;
}
}
else //半角
{
for( p = (const unsigned char *)KUTOTEN_1; *p; p++ )
{
if( *p == c1 ) return true;
}
}
return false;
}
bool CLayoutMgr::IsKinsokuKuto( const char *pLine, int length )
{
const unsigned char *p;
if( length == 1 ) p = (const unsigned char *)m_pszKinsokuKuto_1;
else if( length == 2 ) p = (const unsigned char *)m_pszKinsokuKuto_2;
else return false;
if( ! p ) return false;
for( ; *p; p += length )
{
if( memcmp( pLine, p, length ) == 0 ) return true;
}
return false;
}
int CLayoutMgr::Match_Quote( char szQuote, int nPos, int nLineLen, const char* pLine )
{
int nCharChars;
int i;
for( i = nPos; i < nLineLen; ++i ){
nCharChars = CMemory::MemCharNext( (const char *)pLine, nLineLen, (const char *)&pLine[i] ) - (const char *)&pLine[i];
if( 0 == nCharChars ){
nCharChars = 1;
}
if( m_nStringType == 0 ){ /* 文字列区切り記号エスケープ方法 0=[\"][\'] 1=[""][''] */
if( 1 == nCharChars && pLine[i] == '\\' ){
++i;
}else
if( 1 == nCharChars && pLine[i] == szQuote ){
return i + 1;
}
}else
if( m_nStringType == 1 ){ /* 文字列区切り記号エスケープ方法 0=[\"][\'] 1=[""][''] */
if( 1 == nCharChars && pLine[i] == szQuote ){
if( i + 1 < nLineLen && pLine[i + 1] == szQuote ){
++i;
}else{
return i + 1;
}
}
}
if( 2 == nCharChars ){
++i;
}
}
return nLineLen;
}
bool CLayoutMgr::CheckColorMODE( int &nCOMMENTMODE, int &nCOMMENTEND, int nPos, int nLineLen, const char* pLine, BOOL bDispSSTRING, BOOL bDispWSTRING )
{
switch( nCOMMENTMODE ){
case COLORIDX_TEXT: // 2002/03/13 novice
if( m_cLineComment.Match( nPos, nLineLen, pLine ) ){
nCOMMENTMODE = COLORIDX_COMMENT; /* 行コメントである */ // 2002/03/13 novice
}else
if( m_cBlockComment.Match_CommentFrom( 0, nPos, nLineLen, pLine ) ){
nCOMMENTMODE = COLORIDX_BLOCK1; /* ブロックコメント1である */ // 2002/03/13 novice
/* この物理行にブロックコメントの終端があるか */
nCOMMENTEND = m_cBlockComment.Match_CommentTo( 0, nPos + (int)lstrlen( m_cBlockComment.getBlockCommentFrom(0) ), nLineLen, pLine );
//#ifdef COMPILE_BLOCK_COMMENT2 //@@@ 2001.03.10 by MIK
}else
if( m_cBlockComment.Match_CommentFrom( 1, nPos, nLineLen, pLine ) ){
nCOMMENTMODE = COLORIDX_BLOCK2; /* ブロックコメント2である */ // 2002/03/13 novice
/* この物理行にブロックコメントの終端があるか */
nCOMMENTEND = m_cBlockComment.Match_CommentTo( 1, nPos + (int)lstrlen( m_cBlockComment.getBlockCommentFrom(1) ), nLineLen, pLine );
//#endif
}else
if( bDispSSTRING && /* シングルクォーテーション文字列を表示する */
pLine[nPos] == '\''
){
nCOMMENTMODE = COLORIDX_SSTRING; /* シングルクォーテーション文字列である */ // 2002/03/13 novice
/* シングルクォーテーション文字列の終端があるか */
nCOMMENTEND = Match_Quote( '\'', nPos + 1, nLineLen, pLine );
}else
if( pLine[nPos] == '"' &&
bDispWSTRING /* ダブルクォーテーション文字列を表示する */
){
nCOMMENTMODE = COLORIDX_WSTRING; /* ダブルクォーテーション文字列である */ // 2002/03/13 novice
/* ダブルクォーテーション文字列の終端があるか */
nCOMMENTEND = Match_Quote( '"', nPos + 1, nLineLen, pLine );
}
break;
case COLORIDX_COMMENT: /* 行コメントである */ // 2002/03/13 novice
break;
case COLORIDX_BLOCK1: /* ブロックコメント1である */ // 2002/03/13 novice
if( 0 == nCOMMENTEND ){
/* この物理行にブロックコメントの終端があるか */
nCOMMENTEND = m_cBlockComment.Match_CommentTo( 0, nPos, nLineLen, pLine );
}else
if( nPos == nCOMMENTEND ){
nCOMMENTMODE = COLORIDX_TEXT; // 2002/03/13 novice
return true;
}
break;
//#ifdef COMPILE_BLOCK_COMMENT2 //@@@ 2001.03.10 by MIK
case COLORIDX_BLOCK2: /* ブロックコメント2である */ // 2002/03/13 novice
if( 0 == nCOMMENTEND ){
/* この物理行にブロックコメントの終端があるか */
nCOMMENTEND = m_cBlockComment.Match_CommentTo( 1, nPos, nLineLen, pLine );
}else
if( nPos == nCOMMENTEND ){
nCOMMENTMODE = COLORIDX_TEXT; // 2002/03/13 novice
return true;
}
break;
//#endif
case COLORIDX_SSTRING: /* シングルクォーテーション文字列である */ // 2002/03/13 novice
if( 0 == nCOMMENTEND ){
/* シングルクォーテーション文字列の終端があるか */
nCOMMENTEND = Match_Quote( '\'', nPos, nLineLen, pLine );
}else
if( nPos == nCOMMENTEND ){
nCOMMENTMODE = COLORIDX_TEXT; // 2002/03/13 novice
return true;
}
break;
case COLORIDX_WSTRING: /* ダブルクォーテーション文字列である */ // 2002/03/13 novice
if( 0 == nCOMMENTEND ){
/* ダブルクォーテーション文字列の終端があるか */
nCOMMENTEND = Match_Quote( '"', nPos, nLineLen, pLine );
}else
if( nPos == nCOMMENTEND ){
nCOMMENTMODE = COLORIDX_TEXT; // 2002/03/13 novice
return true;
}
break;
}
return false;
}
/*!
@brief 行の長さを計算する (2行目以降の字下げ無し)
字下げを行わないので,常に0を返す.
引数は使わない.
@return 1行の表示文字数 (常に0)
@author genta
@date 2002.10.01
*/
int CLayoutMgr::getIndentOffset_Normal( CLayout* )
{
return 0;
}
/*!
@brief インデント幅を計算する (Tx2x)
前の行の最後のTABの位置をインデント位置として返す.
ただし,残り幅が6文字未満の場合はインデントを行わない.
@author Yazaki
@return インデントすべき文字数
@date 2002.10.01
@date 2002.10.07 YAZAKI 名称変更, 処理見直し
*/
int CLayoutMgr::getIndentOffset_Tx2x( CLayout* pLayoutPrev )
{
// 前の行が無いときは、インデント不要。
if ( pLayoutPrev == NULL ) return 0;
int nIpos = pLayoutPrev->GetIndent();
// 前の行が折り返し行ならばそれに合わせる
if( pLayoutPrev->m_nOffset > 0 )
return nIpos;
CMemoryIterator<CLayout> it( pLayoutPrev, m_nTabSpace );
while( !it.end() ){
it.scanNext();
if ( it.getIndexDelta() == 1 && it.getCurrentChar() == TAB ){
nIpos = it.getColumn() + it.getColumnDelta();
}
it.addDelta();
}
if ( m_nMaxLineSize - nIpos < 6 ){
nIpos = pLayoutPrev->GetIndent(); // あきらめる
}
return nIpos; // インデント
}
/*!
@brief インデント幅を計算する (スペース字下げ版)
論理行行頭のホワイトスペースの終わりインデント位置として返す.
ただし,残り幅が6文字未満の場合はインデントを行わない.
@author genta
@return インデントすべき文字数
@date 2002.10.01
*/
int CLayoutMgr::getIndentOffset_LeftSpace( CLayout* pLayoutPrev )
{
// 前の行が無いときは、インデント不要。
if ( pLayoutPrev == NULL ) return 0;
// インデントの計算
int nIpos = pLayoutPrev->GetIndent();
// Oct. 5, 2002 genta
// 折り返しの3行目以降は1つ前の行のインデントに合わせる.
if( pLayoutPrev->m_nOffset > 0 )
return nIpos;
// 2002.10.07 YAZAKI インデントの計算
CMemoryIterator<CLayout> it( pLayoutPrev, m_nTabSpace );
// Jul. 20, 2003 genta 自動インデントに準じた動作にする
bool bZenSpace = m_pcEditDoc->GetDocumentAttribute().m_bAutoIndent_ZENSPACE != FALSE ? 1 : 0;
const char* szSpecialIndentChar = m_pcEditDoc->GetDocumentAttribute().m_szIndentChars;
while( !it.end() ){
it.scanNext();
if (( it.getIndexDelta() == 1 && (it.getCurrentChar() == TAB || it.getCurrentChar() == ' ') ) ||
// Jul. 20, 2003 genta 全角スペース対応
( bZenSpace && it.getIndexDelta() == 2 &&
it.getCurrentChar() == (char)0x81 && it.getCurrentPos()[1] == (char)0x40 ))
{
// インデントのカウントを継続する
}
// Jul. 20, 2003 genta インデント対象文字
else if( szSpecialIndentChar[0] != '\0' ){
unsigned char buf[3]; // 文字の長さは1 or 2
memcpy( buf, it.getCurrentPos(), it.getIndexDelta() );
buf[ it.getIndexDelta() ] = '\0';
if( NULL != _mbsstr( (const unsigned char*)szSpecialIndentChar, buf )){
// インデントのカウントを継続する
}
else {
nIpos = it.getColumn(); // 終了
break;
}
}
else {
nIpos = it.getColumn(); // 終了
break;
}
it.addDelta();
}
if ( m_nMaxLineSize - nIpos < 6 ){
nIpos = pLayoutPrev->GetIndent(); // あきらめる
}
return nIpos; // インデント
}
/*[EOF]*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -