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

📄 ceditview_new2.cpp

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



/* テキスト表示
	@@@ 2002.09.22 YAZAKI const unsigned char* pDataを、const char* pDataに変更
*/
int CEditView::DispText( HDC hdc, int x, int y, const char* pData, int nLength )
{
	if( 0 >= nLength ){
		return 0;
	}
	RECT	rcClip;
	int		nLineHeight = m_nCharHeight + m_pcEditDoc->GetDocumentAttribute().m_nLineSpace;
	int		nCharWidth = m_nCharWidth + m_pcEditDoc->GetDocumentAttribute().m_nColmSpace;
	UINT	fuOptions = ETO_CLIPPED | ETO_OPAQUE;
	rcClip.left = x;
	rcClip.right = rcClip.left + ( nCharWidth ) * nLength;
	rcClip.top = y;
	if( rcClip.left < m_nViewAlignLeft ){
		rcClip.left = m_nViewAlignLeft;
	}
	if( rcClip.left < rcClip.right
	 && rcClip.left < m_nViewAlignLeft + m_nViewCx && rcClip.right > m_nViewAlignLeft
	 && rcClip.top >= m_nViewAlignTop
	){
		rcClip.bottom = y + nLineHeight;

		//@@@	From Here 2002.01.30 YAZAKI ExtTextOutの制限回避
		if( rcClip.right - rcClip.left > m_nViewCx ){
			rcClip.right = rcClip.left + m_nViewCx;
		}
		int nBefore = 0;	//	ウィンドウの左にあふれた文字数
		int nAfter = 0;		//	ウィンドウの右にあふれた文字数
		if ( x < 0 ){
			int nLeft = ( 0 - x ) / nCharWidth - 1;
			while (nBefore < nLeft){
				nBefore += CMemory::MemCharNext( pData, nLength, &pData[nBefore] ) - &pData[nBefore];
			}
		}
		if ( rcClip.right < x + nCharWidth * nLength ){
			//	-1してごまかす(うしろはいいよね?)
			nAfter = (x + nCharWidth * nLength - rcClip.right) / nCharWidth - 1;
		}
		::ExtTextOut( hdc, x + nBefore * nCharWidth, y, fuOptions, &rcClip, &pData[nBefore], nLength - nBefore - nAfter, m_pnDx );
		//@@@	To Here 2002.01.30 YAZAKI ExtTextOutの制限回避
	}
	return nLength;

}


/* テキスト反転 */
void CEditView::DispTextSelected( HDC hdc, int nLineNum, int x, int y, int nX  )
{
//	MYTRACE( "CEditView::DispTextSelected()\n" );

	int			nROP_Old;
	int			nSelectFrom;
	int			nSelectTo;
	RECT		rcClip;
//	HPEN		hPen;
//	HPEN		hPenOld;
	HBRUSH		hBrush;
	HBRUSH		hBrushOld;
	int			nLineHeight = m_nCharHeight + m_pcEditDoc->GetDocumentAttribute().m_nLineSpace;
	int			nCharWidth = m_nCharWidth + m_pcEditDoc->GetDocumentAttribute().m_nColmSpace;
	HRGN		hrgnDraw;
	const CLayout* pcLayout = m_pcEditDoc->m_cLayoutMgr.Search( nLineNum );

	/* 選択範囲内の行かな */
//	if( IsTextSelected() ){
		if( nLineNum >= m_nSelectLineFrom && nLineNum <= m_nSelectLineTo ){
			if( m_bBeginBoxSelect){		/* 矩形範囲選択中 */
				nSelectFrom = m_nSelectColmFrom;
				nSelectTo   = m_nSelectColmTo;
			}else{
				if( m_nSelectLineFrom == m_nSelectLineTo ){
						nSelectFrom = m_nSelectColmFrom;
						nSelectTo   = m_nSelectColmTo;
				}else{
					if( nLineNum == m_nSelectLineFrom ){
						nSelectFrom = m_nSelectColmFrom;
						nSelectTo   = nX;
					}else
					if( nLineNum == m_nSelectLineTo ){
						nSelectFrom = pcLayout ? pcLayout->GetIndent() : 0;
						nSelectTo   = m_nSelectColmTo;
					}else{
						nSelectFrom = pcLayout ? pcLayout->GetIndent() : 0;
						nSelectTo   = nX;
					}
				}
			}
			if( nSelectFrom < m_nViewLeftCol ){
				nSelectFrom = m_nViewLeftCol;
			}
			if( nSelectTo < m_nViewLeftCol ){
				nSelectTo = m_nViewLeftCol;
			}
			rcClip.left   = x + nSelectFrom * ( nCharWidth );
			rcClip.right  = x + nSelectTo   * ( nCharWidth );
			rcClip.top    = y;
			rcClip.bottom = y + nLineHeight;
			// 2005/04/02 かろと 0文字マッチだと反転幅が0となり反転されないので、1/3文字幅だけ反転させる
			if (rcClip.right == rcClip.left) {
				rcClip.right = rcClip.left + (nCharWidth/3 == 0 ? 1 : nCharWidth/3);
			}
			if( rcClip.right - rcClip.left > 3000 ){
				rcClip.right = rcClip.left + 3000;
			}
			hBrush = ::CreateSolidBrush( SELECTEDAREA_RGB );
			nROP_Old = ::SetROP2( hdc, SELECTEDAREA_ROP2 );
			hBrushOld = (HBRUSH)::SelectObject( hdc, hBrush );
			hrgnDraw = ::CreateRectRgn( rcClip.left, rcClip.top, rcClip.right, rcClip.bottom );
			::PaintRgn( hdc, hrgnDraw );
			::DeleteObject( hrgnDraw );
			SetROP2( hdc, nROP_Old );
			SelectObject( hdc, hBrushOld );
			DeleteObject( hBrush );
		}
//	}
	return;
}




/* 現在位置が検索文字列に該当するか */
//2002.02.08 hor
//正規表現で検索したときの速度改善のため、マッチ先頭位置を引数に追加
BOOL CEditView::IsSearchString( const char* pszData, int nDataLen, int nPos, int* pnSearchStart, int* pnSearchEnd )
{
	int		nKeyLength;

	//	From Here Jun. 26, 2001 genta	正規表現ライブラリの差し替え
	*pnSearchStart = nPos;	// 2002.02.08 hor

	if( m_bCurSrchRegularExp ){
		/* 行頭ではない? */
		/* 行頭検索チェックは、CBregexpクラス内部で実施するので不要 2003.11.01 かろと */

		/* 位置を0でMatchInfo呼び出すと、行頭文字検索時に、全て true となり、
		** 画面全体が検索文字列扱いになる不具合修正
		** 対策として、行頭を MacthInfoに教えないといけないので、文字列の長さ?位置情報を与える形に変更
		** 2003.05.04 かろと
		*/
		if( m_CurRegexp.Match( pszData, nDataLen, nPos )
		){
			*pnSearchStart = m_CurRegexp.GetIndex();	// 2002.02.08 hor
			*pnSearchEnd = m_CurRegexp.GetLastIndex();
	//	To Here Jun. 26, 2001 genta
			return TRUE;

		}else{
			return FALSE;
		}
	}else{
		nKeyLength = lstrlen( m_szCurSrchKey );		/* 検索条件 */

		// 2001/06/23 単語単位の検索のために追加
		if( m_pShareData->m_Common.m_bWordOnly ){	/* 検索/置換  1==単語のみ検索 */
			/* 現在位置の単語の範囲を調べる */
			/* 現在位置の単語の範囲を調べる */
			int nIdxFrom, nIdxTo;
			if( false == CDocLineMgr::WhereCurrentWord_2( pszData, nDataLen, nPos, &nIdxFrom, &nIdxTo, NULL, NULL ) ){
				return FALSE;
			}
			if( nPos != nIdxFrom || nKeyLength != nIdxTo - nIdxFrom ){
				return FALSE;
			}
		}

		//検索条件が未定義 または 検索条件の長さより調べるデータが短いときはヒットしない
		if( 0 == nKeyLength || nKeyLength > nDataLen - nPos ){
			return FALSE;
		}
		//英大文字小文字の区別をするかどうか
		if( m_bCurSrchLoHiCase ){	/* 1==英大文字小文字の区別 */
			if( 0 == memcmp( &pszData[nPos], m_szCurSrchKey, nKeyLength ) ){
				*pnSearchEnd = nPos + nKeyLength;
				return TRUE;
			}
		}else{
			if( 0 == memicmp( &pszData[nPos], m_szCurSrchKey, nKeyLength ) ){
				*pnSearchEnd = nPos + nKeyLength;
				return TRUE;
			}
		}
	}
	return FALSE;
}

/*! 
	ルーラーのキャレットを再描画	2002.02.25 Add By KK
	@param hdc [in] デバイスコンテキスト
	DispRulerの内容を元に作成
*/
inline void CEditView::DrawRulerCaret( HDC hdc )
{
	HBRUSH		hBrush;
	HBRUSH		hBrushOld;
	HRGN		hRgn;
	RECT		rc;
	int			nROP_Old;

	if( m_nViewLeftCol <= m_nCaretPosX
	 && m_nViewLeftCol + m_nViewColNum + 2 >= m_nCaretPosX
	){
		if (m_nOldCaretPosX == m_nCaretPosX && m_nCaretWidth == m_nOldCaretWidth) {
			//前描画した位置画同じ かつ ルーラーのキャレット幅が同じ 
			return;
		}

		rc.left = m_nViewAlignLeft + ( m_nOldCaretPosX - 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;

		//元位置をクリア m_nOldCaretWidth
		if( 0 == m_nOldCaretWidth ){
			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 );
		::DeleteObject( hRgn );
		::SelectObject( hdc, hBrushOld );
		::DeleteObject( hBrush );

		if( 0 == m_nCaretWidth ){
			hBrush = ::CreateSolidBrush( RGB( 128, 128, 128 ) );
		}else{
			hBrush = ::CreateSolidBrush( RGB( 0, 0, 0 ) );
		}

		//新しい位置で描画
		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;

		hRgn = ::CreateRectRgnIndirect( &rc );
		hBrushOld = (HBRUSH)::SelectObject( hdc, hBrush );
		::SelectObject( hdc, hBrush );
		::PaintRgn( hdc, hRgn );

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



/*! ルーラー描画 */
void CEditView::DispRuler( HDC hdc )
{

#ifdef _DEBUG
//	if( 0 != m_pShareData->m_Common.m_nRulerType ){	/* ルーラーのタイプ */
//		DispRulerEx( hdc );
//		return;
//	}
#endif


	if( !m_bDrawSWITCH ){
		return;
	}
	if( !m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[COLORIDX_RULER].m_bDisp ){
		return;
	}

	// 2002.02.25 Add By KK ルーラー全体を描き直す必要がない場合は、ルーラ上のキャレットのみ描きなおす 
	if ( !m_bRedrawRuler ) {
		DrawRulerCaret( hdc );
	}
	else {
		/* 描画処理 */
		HBRUSH		hBrush;
		HBRUSH		hBrushOld;
		HRGN		hRgn;
		RECT		rc;
		int			i;
		int			nX;
		int			nY;
		LOGFONT		lf;
		HFONT		hFont;
 		HFONT		hFontOld;
		char		szColm[32];

		HPEN		hPen;
		HPEN		hPenOld;
		int			nROP_Old;
		COLORREF	colTextOld;
		int			nToX;

		/* LOGFONTの初期化 */
		memset( &lf, 0, sizeof(LOGFONT) );
		lf.lfHeight			= 1 - m_pShareData->m_Common.m_nRulerHeight;	//	2002/05/13 ai
		lf.lfWidth			= 5/*0*/;
		lf.lfEscapement		= 0;
		lf.lfOrientation	= 0;
		lf.lfWeight			= 400;
		lf.lfItalic			= 0;
		lf.lfUnderline		= 0;
		lf.lfStrikeOut		= 0;
		lf.lfCharSet		= 0;
		lf.lfOutPrecision	= 3;
		lf.lfClipPrecision	= 2;
		lf.lfQuality		= 1;
		lf.lfPitchAndFamily	= 34;
		strcpy( lf.lfFaceName, "Arial" );
		hFont = ::CreateFontIndirect( &lf );
		hFontOld = (HFONT)::SelectObject( hdc, hFont );
		::SetBkMode( hdc, TRANSPARENT );

		hBrush = ::CreateSolidBrush( m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[COLORIDX_RULER].m_colBACK );
		rc.left = 0;
		rc.top = 0;
		rc.right = m_nViewAlignLeft + m_nViewCx;
		rc.bottom = m_nViewAlignTop - m_nTopYohaku;
		::FillRect( hdc, &rc, hBrush );
		::DeleteObject( hBrush );

		nX = m_nViewAlignLeft;
		nY = m_nViewAlignTop - m_nTopYohaku - 2;

		hPen = ::CreatePen( PS_SOLID, 0, m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[COLORIDX_RULER].m_colTEXT );
		hPenOld = (HPEN)::SelectObject( hdc, hPen );
		colTextOld = ::SetTextColor( hdc, m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[COLORIDX_RULER].m_colTEXT );


		nToX = m_nViewAlignLeft + m_nViewCx;

		nToX = m_nViewAlignLeft + (m_pcEditDoc->GetDocumentAttribute().m_nMaxLineSize - m_nViewLeftCol) * ( m_nCharWidth  + m_pcEditDoc->GetDocumentAttribute().m_nColmSpace );
		if( nToX > m_nViewAlignLeft + m_nViewCx ){
			nToX = m_nViewAlignLeft + m_nViewCx;
		}
		::MoveToEx( hdc, m_nViewAlignLeft, nY + 1, NULL );
		::LineTo( hdc, nToX/*m_nViewAlignLeft + m_nViewCx*/, nY + 1 );


		for( i = m_nViewLeftCol;
			i <= m_nViewLeftCol + m_nViewColNum + 1
		 && i <= m_pcEditDoc->GetDocumentAttribute().m_nMaxLineSize;
			i++
		){
			if( i == m_pcEditDoc->GetDocumentAttribute().m_nMaxLineSize ){
				::MoveToEx( hdc, nX, nY, NULL );
				::LineTo( hdc, nX, 0/*nY - 8*/ );
			}
			if( 0 == ( (i) % 10 ) ){
				::MoveToEx( hdc, nX, nY, NULL );
				::LineTo( hdc, nX, 0/*nY - 8*/ );
				itoa( (i) / 10, szColm, 10 );
				::TextOut( hdc, nX + 2 + 0, -1 + 0, szColm, lstrlen( szColm ) );
			}else
			if( 0 == ( (i) % 5 ) ){
				::MoveToEx( hdc, nX, nY, NULL );
				::LineTo( hdc, nX, nY - 6 );
			}else{
				::MoveToEx( hdc, nX, nY, NULL );
				::LineTo( hdc, nX, nY - 3 );
			}
			nX += ( m_nCharWidth + m_pcEditDoc->GetDocumentAttribute().m_nColmSpace );
		}
		::SetTextColor( hdc, colTextOld );
		::SelectObject( hdc, hPenOld );
		::DeleteObject( hPen );

⌨️ 快捷键说明

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