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

📄 ceditview_new2.cpp

📁 日本的开源编辑器源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:

		/* キャレット描画(現在の位置に描画するだけ。古い位置はすでに消されている) */
		if( m_nViewLeftCol <= m_nCaretPosX
		 && m_nViewLeftCol + m_nViewColNum + 2 >= m_nCaretPosX
		){
			//	Aug. 18, 2000 あお
			rc.left = m_nViewAlignLeft + ( m_nCaretPosX - m_nViewLeftCol ) * ( m_nCharWidth + m_pcEditDoc->GetDocumentAttribute().m_nColmSpace ) + 1;
			rc.right = rc.left + m_nCharWidth + m_pcEditDoc->GetDocumentAttribute().m_nColmSpace - 1;
			rc.top = 0;
			rc.bottom = m_nViewAlignTop - m_nTopYohaku - 1;

			if( 0 == m_nCaretWidth ){
				hBrush = ::CreateSolidBrush( RGB( 128, 128, 128 ) );
			}else{
				hBrush = ::CreateSolidBrush( RGB( 0, 0, 0 ) );
			}
			nROP_Old = ::SetROP2( hdc, R2_NOTXORPEN );
			hRgn = ::CreateRectRgnIndirect( &rc );
			hBrushOld = (HBRUSH)::SelectObject( hdc, hBrush );
			::PaintRgn( hdc, hRgn );

			::SelectObject( hdc, hBrushOld );
			::DeleteObject( hRgn );
			::DeleteObject( hBrush );
			::SetROP2( hdc, nROP_Old );
		}

		::SelectObject( hdc, hFontOld );
		::DeleteObject( hFont );

		m_bRedrawRuler = false;	//m_bRedrawRuler = true で指定されるまで、ルーラのキャレットのみを再描画 2002.02.25 Add By KK
	}

	//描画したルーラーのキャレット位置?幅を保存 2002.02.25 Add By KK
	m_nOldCaretPosX = m_nCaretPosX;
	m_nOldCaretWidth = m_nCaretWidth ;

	return;
}

//======================================================================
//@@@ 2001.02.03 Start by MIK: 全角文字の対括弧
//! 全角括弧の対応表
const struct ZENKAKKO_T{
	char *sStr;
	char *eStr;
} zenkakkoarr[] = {
	"【", "】",
	"『", "』",
	"「", "」",
	"<", ">",
	"?", "?",
	"《", "》",
	"(", ")",
	"〈", "〉",
	"{", "}",
	"〔", "〕",
	"[", "]",
	"“", "”",
	"〝", "?",
	NULL, NULL	//終端識別
};
//@@@ 全角文字の対括弧: End
//@@@ 2003.01.06 Start by ai: 半角文字の対括弧
//! 半角括弧の対応表
const struct HANKAKKO_T{
	char *sStr;
	char *eStr;
} hankakkoarr[] = {
	"(", ")",
	"[", "]",
	"{", "}",
	"<", ">",
	"?", "?",
	NULL, NULL	//終端識別
};
//@@@ 半角文字の対括弧: End
//	Jun. 16, 2000 genta
/*!
	@brief 対括弧の検索

	カーソル位置の括弧に対応する括弧を探す。カーソル位置が括弧でない場合は
	カーソルの後ろの文字が括弧かどうかを調べる。

	カーソルの前後いずれもが括弧でない場合は何もしない。

	括弧が半角か全角か、及び始まりか終わりかによってこれに続く4つの関数に
	制御を移す。

	@param LayoutX [in] 検索開始点の物理座標X
	@param LayoutY [in] 検索開始点の物理座標Y
	@param NewX [out] 移動先のレイアウト座標X
	@param NewY [out] 移動先のレイアウト座標Y
	@param mode [in/out] bit0(in)  : 表示領域外を調べるか? 0:調べない  1:調べる
						 bit1(in)  : 前方文字を調べるか?   0:調べない  1:調べる (このbitを参照)
						 bit2(out) : 見つかった位置         0:後ろ      1:前     (このbitを更新)

	@retval true 成功
	@retval false 失敗

	@author genta
	@date Jun. 16, 2000 genta
	@date Feb. 03, 2001 MIK 全角括弧に対応
	@date Sep. 18, 2002 ai modeの追加
*/
bool CEditView::SearchBracket( int LayoutX, int LayoutY, int* NewX, int* NewY, int* mode )
{
	int len;	//	行の長さ
	int nCharSize;	//	(メモリ上の)文字幅
	int PosX, PosY;	//	物理位置

	m_pcEditDoc->m_cLayoutMgr.CaretPos_Log2Phys( LayoutX, LayoutY, &PosX, &PosY );
	const char *cline = m_pcEditDoc->m_cDocLineMgr.GetLineStr( PosY, &len );

	//	Jun. 19, 2000 genta
	if( cline == NULL )	//	最後の行に本文がない場合
		return false;
//	PosX = LineColmnToIndex( cline, len, PosX );	不要

	nCharSize = CMemory::MemCharNext( cline, len, cline + PosX ) - cline - PosX;
	m_nCharSize = nCharSize;	// 02/09/18 対括弧の文字サイズ設定 ai

	if( nCharSize == 1 ){	//	1バイト文字
		// 03/01/06 ai Start
		int i;
		const struct HANKAKKO_T *p;
		p = hankakkoarr;
		for( i = 0; p->sStr != NULL; i++, p++ )
		{
			if( strncmp(p->sStr, &cline[PosX], 1) == 0 )
			{
				return SearchBracketForward( PosX, PosY, NewX, NewY, p->sStr, p->eStr, mode );
			}
			else if( strncmp(p->eStr, &cline[PosX], 1) == 0 )
			{
				return SearchBracketBackward( PosX, PosY, NewX, NewY, p->sStr, p->eStr, mode );
			}
		}
		// 03/01/06 ai End
//@@@ 2001.02.03 Start by MIK: 全角文字の対括弧
	}else if( nCharSize == 2 ){	// 2バイト文字
		int i;
		const struct ZENKAKKO_T *p;
		p = zenkakkoarr;
		for(i = 0; p->sStr != NULL; i++, p++)
		{
			if(strncmp(p->sStr, &cline[PosX], 2) == 0)
			{
				return SearchBracketForward2( PosX, PosY, NewX, NewY, p->sStr, p->eStr, mode );		// modeの追加 02/09/19 ai
			}
			else if(strncmp(p->eStr, &cline[PosX], 2) == 0)
			{
				return SearchBracketBackward2( PosX, PosY, NewX, NewY, p->sStr, p->eStr, mode );	// modeの追加 02/09/19 ai
			}
		}
//@@@ 2001.02.03 End: 全角文字の対括弧
	}

	// 02/09/18 ai Start
	if( 0 == ( *mode & 2 ) ){
		/* カーソルの前方を調べない場合 */
		return false;
	}
	*mode |= 4;
	// 02/09/18 ai End

	//	括弧が見つからなかったら,カーソルの直前の文字を調べる

	if( PosX <= 0 ){
//		::MessageBox( NULL, "NO DATA", "Bracket", MB_OK );
		return false;	//	前の文字はない
	}
	const char *bPos = CMemory::MemCharPrev( cline, PosX, cline + PosX );
	nCharSize = cline + PosX - bPos;
	m_nCharSize = nCharSize;	// 02/10/01 対括弧の文字サイズ設定 ai
	if( nCharSize == 1 ){	//	1バイト文字
		// 03/01/06 ai Start
		int i;
		const struct HANKAKKO_T *p;
		PosX = bPos - cline;
		p = hankakkoarr;
		for( i = 0; p->sStr != NULL; i++, p++ )
		{
			if( strncmp(p->sStr, &cline[PosX], 1) == 0 )
			{
				return SearchBracketForward( PosX, PosY, NewX, NewY, p->sStr, p->eStr, mode );
			}
			else if( strncmp(p->eStr, &cline[PosX], 1) == 0 )
			{
				return SearchBracketBackward( PosX, PosY, NewX, NewY, p->sStr, p->eStr, mode );
			}
		}
		// 03/01/06 ai End
//@@@ 2001.02.03 Start by MIK: 全角文字の対括弧
	}else if( nCharSize == 2 ){	// 2バイト文字
		int i;
		const struct ZENKAKKO_T *p;
		PosX = bPos - cline;
		p = zenkakkoarr;
		for( i = 0; p->sStr != NULL; i++, p++ )
		{
			if( strncmp(p->sStr, &cline[PosX], 2) == 0 )
			{
				return SearchBracketForward2( PosX, PosY, NewX, NewY, p->sStr, p->eStr, mode );		// modeの追加 02/09/19 ai
			}
			else if( strncmp(p->eStr, &cline[PosX], 2) == 0 )
			{
				return SearchBracketBackward2( PosX, PosY, NewX, NewY, p->sStr, p->eStr, mode );	// modeの追加 02/09/19 ai
			}
		}
//@@@ 2001.02.03 End: 全角文字の対括弧
	}
	return false;
}

/*!
	@brief 半角対括弧の検索:順方向

	@author genta

	@param PosX [in] 検索開始点の物理座標X
	@param PosY [in] 検索開始点の物理座標Y
	@param NewX [out] 移動先のレイアウト座標X
	@param NewY [out] 移動先のレイアウト座標Y
	@param upChar [in] 括弧の始まりの文字
	@param dnChar [in] 括弧を閉じる文字列
	@param mode [in] bit0(in)  : 表示領域外を調べるか? 0:調べない  1:調べる (このbitを参照)
					 bit1(in)  : 前方文字を調べるか?   0:調べない  1:調べる
					 bit2(out) : 見つかった位置         0:後ろ      1:前

	@retval true 成功
	@retval false 失敗
*/
bool CEditView::SearchBracketForward( int PosX, int PosY, int* NewX, int* NewY,
									char* upChar, char* dnChar, int* mode )	// 03/01/08 ai
{
	CDocLine* ci;

	int			len;
	const char	*cPos, *nPos;
	char		*cline, *lineend;
	int			level = 0;
	int			nCol, nLine, nSearchNum;	// 02/09/19 ai

//	char buf[50];	Debug用

	//	初期位置の設定
	m_pcEditDoc->m_cLayoutMgr.CaretPos_Phys2Log( PosX, PosY, &nCol, &nLine );	// 02/09/19 ai
	nSearchNum = ( m_nViewTopLine + m_nViewRowNum ) - nLine;					// 02/09/19 ai
	ci = m_pcEditDoc->m_cDocLineMgr.GetLineInfo( PosY );
	cline = ci->m_pLine->GetPtr( &len );
	lineend = cline + len;
	cPos = cline + PosX;

	do {
		while( cPos < lineend ){
			nPos = CMemory::MemCharNext( cline, len, cPos );
			if( nPos - cPos > 1 ){
				//	skip
				cPos = nPos;
				continue;
			}
			// 03/01/08 ai Start
			if( strncmp(upChar, cPos, 1) == 0 ){
				++level;
			}
			else if( strncmp(dnChar, cPos, 1) == 0 ){
				--level;
			}// 03/01/08 ai End

			if( level == 0 ){	//	見つかった!
				PosX = cPos - cline;
				m_pcEditDoc->m_cLayoutMgr.CaretPos_Phys2Log( PosX, PosY, NewX, NewY );
//				wsprintf( buf, "Layout: %d, %d\nPhys: %d, %d", *NewX, *NewY, PosX, PosY );
//				::MessageBox( NULL, buf, "Bracket", MB_OK );
				return true;
				//	Happy Ending
			}
			cPos = nPos;	//	次の文字へ
		}

		// 02/09/19 ai Start
		nSearchNum--;
		if( ( 0 > nSearchNum ) && ( 0 == (*mode & 1 ) ) )
		{	// 表示領域外を調べないモードで表示領域の終端の場合
			//SendStatusMessage( "対括弧の検索を中断しました" );
			break;
		}
		// 02/09/19 ai End

		//	次の行へ
		++PosY;
		ci = ci->m_pNext;	//	次のアイテム
		if( ci == NULL )
			break;	//	終わりに達した

		cline = ci->m_pLine->GetPtr( &len );
		cPos = cline;
		lineend = cline + len;
	}while( cline != NULL );

	return false;
}

/*!
	@brief 半角対括弧の検索:逆方向

	@author genta

	@param PosX [in] 検索開始点の物理座標X
	@param PosY [in] 検索開始点の物理座標Y
	@param NewX [out] 移動先のレイアウト座標X
	@param NewY [out] 移動先のレイアウト座標Y
	@param upChar [in] 括弧の始まりの文字
	@param dnChar [in] 括弧を閉じる文字列
	@param mode [in] bit0(in)  : 表示領域外を調べるか? 0:調べない  1:調べる (このbitを参照)
					 bit1(in)  : 前方文字を調べるか?   0:調べない  1:調べる
					 bit2(out) : 見つかった位置         0:後ろ      1:前

	@retval true 成功
	@retval false 失敗
*/
bool CEditView::SearchBracketBackward( int PosX, int PosY, int* NewX, int* NewY,
									char* dnChar, char* upChar, int* mode )
{
	CDocLine* ci;

	int			len;
	const char	*cPos, *pPos;
	char		*cline, *lineend;
	int			level = 1;
	int			nCol, nLine, nSearchNum;	// 02/09/19 ai

//	char buf[50];	Debug用

	//	初期位置の設定
	m_pcEditDoc->m_cLayoutMgr.CaretPos_Phys2Log( PosX, PosY, &nCol, &nLine );	// 02/09/19 ai
	nSearchNum = nLine - m_nViewTopLine;										// 02/09/19 ai
	ci = m_pcEditDoc->m_cDocLineMgr.GetLineInfo( PosY );
	cline = ci->m_pLine->GetPtr( &len );
	lineend = cline + len;
	cPos = cline + PosX;

	do {
		while( cPos > cline ){
			pPos = CMemory::MemCharPrev( cline, len, cPos );
			if( cPos - pPos > 1 ){
				//	skip
				cPos = pPos;
				continue;
			}
			// 03/01/08 ai Start
			if( strncmp(upChar, pPos, 1) == 0 ){
				++level;
			}
			else if( strncmp(dnChar, pPos, 1) == 0 ){
				--level;
			}// 03/01/08 ai End

			if( level == 0 ){	//	見つかった!
				PosX = pPos - cline;
				m_pcEditDoc->m_cLayoutMgr.CaretPos_Phys2Log( PosX, PosY, NewX, NewY );
//				wsprintf( buf, "Layout: %d, %d\nPhys: %d, %d", *NewX, *NewY, PosX, PosY );
//				::MessageBox( NULL, buf, "Bracket", MB_OK );
				return true;
				//	Happy Ending
			}
			cPos = pPos;	//	次の文字へ
		}

		// 02/09/19 ai Start
		nSearchNum--;
		if( ( 0 > nSearchNum ) && ( 0 == (*mode & 1 ) ) )
		{	// 表示領域外を調べないモードで表示領域の先頭の場合
			//SendStatusMessage( "対括弧の検索を中断しました" );

⌨️ 快捷键说明

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