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

📄 ceditview_new2.cpp

📁 日本的开源编辑器源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//	$Id: CEditView_New2.cpp,v 1.37 2005/04/17 10:01:03 genta Exp $
/*!	@file
	@brief CEditViewクラス

	@author Norio Nakatani
	@date	1998/12/08 作成
	$Revision: 1.37 $
*/
/*
	Copyright (C) 1998-2001, Norio Nakatani
	Copyright (C) 2000-2001, genta, mik, asa-o
	Copyright (C) 2001, hor, MIK 
	Copyright (C) 2002, YAZAKI, aroka, MIK

	This source code is designed for sakura editor.
	Please contact the copyright holders to use this code for other purpose.
*/

#include <stdlib.h>
#include <time.h>
#include <io.h>
#include "CEditView.h"
#include "debug.h"
#include "funccode.h"
#include "charcode.h"
#include "mymessage.h"
#include "CEditWnd.h"
#include "CShareData.h"
#include "CDlgCancel.h"
#include "sakura_rc.h"
#include "etc_uty.h"
#include "Clayout.h" /// 2002/2/3 aroka
#include "CDocLine.h" /// 2002/2/3 aroka
#include "CMarkMgr.h" /// 2002/2/3 aroka
#include "my_icmp.h"	//@@@ 2002.01.13 add


/* 現在の色を指定 */
void CEditView::SetCurrentColor( HDC hdc, int nCOMMENTMODE )
{
	int				nColorIdx;
	COLORREF		colText;
	COLORREF		colBack;
//	if( NULL != m_hFontOld ){
//		::SelectObject( hdc, m_hFontOld );
//		m_hFontOld = NULL;
//	}
	nColorIdx = -1;
	switch( nCOMMENTMODE ){
// 2002/03/13 novice
	case COLORIDX_TEXT: /* テキスト */
	case COLORIDX_SSTRING:	/* シングルクォーテーション文字列である */
	case COLORIDX_WSTRING:	/* ダブルクォーテーション文字列である */
	case COLORIDX_CTRLCODE:	/* コントロールコードである */
	case COLORIDX_DIGIT:	/* 半角数値である */
	case COLORIDX_KEYWORD1:	/* 強調キーワード1(登録単語)文字列である */
	case COLORIDX_KEYWORD2:	/* 強調キーワード2(登録単語)文字列である */
	case COLORIDX_KEYWORD3:	// 2005.01.13 MIK 強調キーワード3-10
	case COLORIDX_KEYWORD4:
	case COLORIDX_KEYWORD5:
	case COLORIDX_KEYWORD6:
	case COLORIDX_KEYWORD7:
	case COLORIDX_KEYWORD8:
	case COLORIDX_KEYWORD9:
	case COLORIDX_KEYWORD10:
	case COLORIDX_URL:	    /* URLである */
	case COLORIDX_SEARCH:	/* 検索文字列である */
	case COLORIDX_BRACKET_PAIR: /* 対括弧の強調表示である */	// 2002/12/18 ai
		nColorIdx = nCOMMENTMODE;
		break;
	case COLORIDX_COMMENT:	/* 行コメントである */
	case COLORIDX_BLOCK1:	/* ブロックコメント1である */
	case COLORIDX_BLOCK2:	/* ブロックコメント2である */	//@@@ 2001.03.10 by MIK
		nColorIdx = COLORIDX_COMMENT;
		break;

//@@@ 2001.11.17 add start MIK
	default:	/* 正規表現キーワード */
		if( nCOMMENTMODE >= 1000 && nCOMMENTMODE <= 1099 )
		{
			nColorIdx = nCOMMENTMODE - 1000;	//下駄を履かせているのをはずす
			colText = m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIdx].m_colTEXT;
			colBack = m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIdx].m_colBACK;
			::SetTextColor( hdc, colText );
			::SetBkColor( hdc, colBack );
			if( NULL != m_hFontOld ){
				::SelectObject( hdc, m_hFontOld );
			}
			/* フォントを選ぶ */
			m_hFontOld = (HFONT)::SelectObject( hdc,
				ChooseFontHandle(
					m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIdx].m_bFatFont,
					m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIdx].m_bUnderLine
				)
			);
			return;
		}
		break;
//@@@ 2001.11.17 add end MIK

	}





	if( -1 != nColorIdx ){
		if( m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIdx].m_bDisp ){
			colText = m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIdx].m_colTEXT;
			colBack = m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIdx].m_colBACK;
			::SetTextColor( hdc, colText );
			::SetBkColor( hdc, colBack );
			if( NULL != m_hFontOld ){
				::SelectObject( hdc, m_hFontOld );
			}
			/* フォントを選ぶ */
			m_hFontOld = (HFONT)::SelectObject( hdc,
				ChooseFontHandle(
					m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIdx].m_bFatFont,
					m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIdx].m_bUnderLine
				)
			);
		}
	}

	return;
}


/* 行番号表示 */
void CEditView::DispLineNumber(
		HDC						hdc,
		const CLayout*			pcLayout,
		int						nLineNum,
		int						y
)
{
	RECT			rcClip;
	HBRUSH			hBrush;
	COLORREF		colTextColorOld;
	COLORREF		colBkColorOld;
	char			szLineNum[18];
	int				nLineHeight = m_nCharHeight + m_pcEditDoc->GetDocumentAttribute().m_nLineSpace;
	int				nCharWidth = m_nCharWidth + m_pcEditDoc->GetDocumentAttribute().m_nColmSpace;
	int				nLineCols;
	UINT			fuOptions = ETO_CLIPPED | ETO_OPAQUE;
	HPEN			hPen, hPenOld;
	int				nColorIndex;
	const CDocLine*	pCDocLine;
	//	Sep. 23, 2002 genta 共通式のくくりだし
	int				nLineNumAreaWidth = m_nViewAlignLeftCols * nCharWidth;

	nColorIndex = COLORIDX_GYOU;	/* 行番号 */
	if( NULL != pcLayout ){
//		pCDocLine = m_pcEditDoc->m_cDocLineMgr.GetLineInfo( pcLayout->m_nLinePhysical );
		pCDocLine = pcLayout->m_pCDocLine;

		if( m_pcEditDoc->IsModified()	/* ドキュメントが無変更の状態か */
		 && pCDocLine->IsModifyed() ){		/* 変更フラグ */
//			if( 0 == pCDocLine->m_nModifyCount ){	/* 変更回数 */
				nColorIndex = COLORIDX_GYOU_MOD;	/* 行番号(変更行) */
//			}
//		}else{
//			if( /* FALSE == m_pcEditDoc->IsModified() && --*/ /* ドキュメントが無変更の状態か */
//				0 < pCDocLine->m_nModifyCount	/* 変更回数 */
//			){
//				nColorIndex = COLORIDX_GYOU_MODSAVE;	/* 行番号(変更&保存済) */
//			}
		}
	}

	int type = pCDocLine->IsDiffMarked();
	{	//DIFF差分マーク表示	//@@@ 2002.05.25 MIK
		if( type )
		{
			switch( type )
			{
			case MARK_DIFF_APPEND:	//追加
				if( m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[COLORIDX_DIFF_APPEND].m_bDisp )
					nColorIndex = COLORIDX_DIFF_APPEND;
				break;
			case MARK_DIFF_CHANGE:	//変更
				if( m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[COLORIDX_DIFF_CHANGE].m_bDisp )
					nColorIndex = COLORIDX_DIFF_CHANGE;
				break;
			case MARK_DIFF_DELETE:	//削除
			case MARK_DIFF_DEL_EX:	//削除
				if( m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[COLORIDX_DIFF_DELETE].m_bDisp )
					nColorIndex = COLORIDX_DIFF_DELETE;
				break;
			}
		}
	}

	/* 02/10/16 ai Start */
	// ブックマークの表示
	if(pCDocLine->IsBookMarked()){
		if( m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[COLORIDX_MARK].m_bDisp ) {
			nColorIndex = COLORIDX_MARK;
		}
	}
	/* 02/10/16 ai End */

//	if( m_pcEditDoc->GetDocumentAttribute().m_bDispLINE ){	/* 行番号表示/非表示 */
	if( m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[/*nColorIndex*/COLORIDX_GYOU].m_bDisp ){	/* 行番号表示/非表示 */
		/* 行番号の表示 FALSE=折り返し単位/TRUE=改行単位 */
		if( m_pcEditDoc->GetDocumentAttribute().m_bLineNumIsCRLF ){
			/* 論理行番号表示モード */
			if( NULL == pcLayout || 0 != pcLayout->m_nOffset ){
				strcpy( szLineNum, " " );
			}else{
				_itoa( pcLayout->m_nLinePhysical + 1, szLineNum, 10 );	/* 対応する論理行番号 */
			}
		}else{
			/* 物理行(レイアウト行)番号表示モード */
			_itoa( nLineNum + 1, szLineNum, 10 );
		}
		nLineCols = lstrlen( szLineNum );

		colTextColorOld = ::SetTextColor( hdc, m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIndex].m_colTEXT );	/* 行番号の色 */
		//	Sep. 23, 2002 余白をテキストの背景色にする
		colBkColorOld = ::SetBkColor( hdc, m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[COLORIDX_TEXT].m_colBACK );		/* テキスト背景の色 */

		HFONT	hFontOld;
		/* フォントを選ぶ */
		hFontOld = (HFONT)::SelectObject( hdc,
			ChooseFontHandle(
				m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIndex].m_bFatFont,
				m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIndex].m_bUnderLine
			)
		);
//		if( m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIndex].m_bFatFont ){	/* 太字か */
//			hFontOld = (HFONT)::SelectObject( hdc, m_hFont_HAN_FAT );
//		}else{
//			hFontOld = (HFONT)::SelectObject( hdc, m_hFont_HAN );
//		}

		/* 余白を埋める */
		rcClip.left = nLineNumAreaWidth;
		rcClip.right = m_nViewAlignLeft;
		rcClip.top = y;
		rcClip.bottom = y + nLineHeight;
		::ExtTextOut( hdc,
			rcClip.left,
			y, fuOptions,
			&rcClip, " ", 1, m_pnDx
		);
		
		//	Sep. 23, 2002 余白をテキストの背景色にするため,背景色の設定を移動
		SetBkColor( hdc, m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIndex].m_colBACK );		/* 行番号背景の色 */

//		/* 行番号のテキストを表示 */
//		m_pShareData->m_Types[nIdx].m_nLineTermType = 1;			/* 行番号区切り 0=なし 1=縦線 2=任意 */
//		m_pShareData->m_Types[nIdx].m_cLineTermChar = ':';			/* 行番号区切り文字 */

		int drawNumTop = (m_nViewAlignLeftCols - nLineCols - 1) * ( nCharWidth );

		/* 行番号区切り 0=なし 1=縦線 2=任意 */
		if( 2 == m_pcEditDoc->GetDocumentAttribute().m_nLineTermType ){
			//	Sep. 22, 2002 genta
			szLineNum[ nLineCols ] = m_pcEditDoc->GetDocumentAttribute().m_cLineTermChar;
			szLineNum[ ++nLineCols ] = '\0';
			//char szLineTerm[2];
			//wsprintf( szLineTerm, "%c", m_pcEditDoc->GetDocumentAttribute().m_cLineTermChar );	/* 行番号区切り文字 */
			//strcat( szLineNum, szLineTerm );
		}
		rcClip.left = 0;
		//rcClip.right = m_nViewAlignLeft/* - 3*/;
		//	Sep. 23, 2002 genta
		rcClip.right = nLineNumAreaWidth;
		rcClip.top = y;
		rcClip.bottom = y + nLineHeight;
		::ExtTextOut( hdc,
			drawNumTop,
			y, fuOptions,
			&rcClip, szLineNum, nLineCols, m_pnDx // Sep. 22, 2002 genta
		);


//		hPen = ::CreatePen( PS_SOLID, 0, m_pcEditDoc->GetDocumentAttribute().m_colorGYOU );


		/* 行番号区切り 0=なし 1=縦線 2=任意 */
		if( 1 == m_pcEditDoc->GetDocumentAttribute().m_nLineTermType ){
			hPen = ::CreatePen( PS_SOLID, 0, m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIndex].m_colTEXT );
			hPenOld = (HPEN)::SelectObject( hdc, hPen );
			::MoveToEx( hdc, nLineNumAreaWidth - 2, y, NULL );
			::LineTo( hdc, nLineNumAreaWidth - 2, y + nLineHeight );
			::SelectObject( hdc, hPenOld );
			::DeleteObject( hPen );
		}
		::SetTextColor( hdc, colTextColorOld );
		::SetBkColor( hdc, colBkColorOld );
		::SelectObject( hdc, hFontOld );
	}else{
		rcClip.left = 0;
		//	Sep. 23 ,2002 genta 余白はテキスト色のまま残す
		rcClip.right = m_nViewAlignLeft - m_pShareData->m_Common.m_nLineNumRightSpace;
		rcClip.top = y;
		rcClip.bottom = y + nLineHeight;
//		hBrush = ::CreateSolidBrush( m_pcEditDoc->GetDocumentAttribute().m_colorBACK );
		hBrush = ::CreateSolidBrush( m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIndex/*COLORIDX_TEXT*/].m_colBACK );
		::FillRect( hdc, &rcClip, hBrush );
		::DeleteObject( hBrush );
		
		// From Here Mar. 5, 2003, Moca
		// 行番号とテキストの隙間の描画漏れ
		rcClip.left = rcClip.right;
		rcClip.right = m_nViewAlignLeft;
		rcClip.top = y;
		rcClip.bottom = y + nLineHeight;
		hBrush = ::CreateSolidBrush( m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[COLORIDX_TEXT].m_colBACK );
		::FillRect( hdc, &rcClip, hBrush );
		::DeleteObject( hBrush );
		// To Here Mar. 5, 2003, Moca
	}

// From Here 2001.12.03 hor
	/* とりあえずブックマークに縦線 */
	if(pCDocLine->IsBookMarked() &&	// Dec. 24, 2002 ai
		(FALSE == m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[COLORIDX_MARK].m_bDisp)){
		hPen = ::CreatePen( PS_SOLID, 2, m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIndex].m_colTEXT );
		hPenOld = (HPEN)::SelectObject( hdc, hPen );
		::MoveToEx( hdc, 1, y, NULL );
		::LineTo( hdc, 1, y + nLineHeight );
		::SelectObject( hdc, hPenOld );
		::DeleteObject( hPen );
	}
// To Here 2001.12.03 hor

	if( type )	//DIFF差分マーク表示	//@@@ 2002.05.25 MIK
	{
		int	cy = y + nLineHeight / 2;

		hPen = ::CreatePen( PS_SOLID, 1, m_pcEditDoc->GetDocumentAttribute().m_ColorInfoArr[nColorIndex].m_colTEXT );
		hPenOld = (HPEN)::SelectObject( hdc, hPen );

		switch( type )
		{
		case MARK_DIFF_APPEND:	//追加
			::MoveToEx( hdc, 3, cy, NULL );
			::LineTo( hdc, 6, cy );
			::MoveToEx( hdc, 4, cy - 2, NULL );
			::LineTo( hdc, 4, cy + 3 );
			break;

		case MARK_DIFF_CHANGE:	//変更
			::MoveToEx( hdc, 3, cy - 4, NULL );
			::LineTo( hdc, 3, cy );
			::MoveToEx( hdc, 3, cy + 2, NULL );
			::LineTo( hdc, 3, cy + 3 );
			break;

		case MARK_DIFF_DELETE:	//削除
			cy -= 3;
			::MoveToEx( hdc, 3, cy, NULL );
			::LineTo( hdc, 5, cy );
			::LineTo( hdc, 3, cy + 2 );
			::LineTo( hdc, 3, cy );
			::LineTo( hdc, 7, cy + 4 );
			break;
		
		case MARK_DIFF_DEL_EX:	//削除(EOF)
			cy += 3;
			::MoveToEx( hdc, 3, cy, NULL );
			::LineTo( hdc, 5, cy );
			::LineTo( hdc, 3, cy - 2 );
			::LineTo( hdc, 3, cy );
			::LineTo( hdc, 7, cy - 4 );
			break;
		}

		::SelectObject( hdc, hPenOld );
		::DeleteObject( hPen );
	}

⌨️ 快捷键说明

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