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

📄 outputwindow.cpp

📁 Crimson编辑器的英文版,完成从韩文版变成英文版的移植,并且附带可执行文件和注册表文件,无需原先的安装包,是改写编辑器的最理想选择.
💻 CPP
字号:
// OutputWindow.cpp : implementation file
//

#include "stdafx.h"
#include "cedtHeader.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


COutputWindow::COutputWindow()
{
	memset( m_tbiToolbarOutput, 0x00, sizeof(m_tbiToolbarOutput) );
	memset( m_tbiWinButtons, 0x00, sizeof(m_tbiWinButtons) );

	m_tbiToolbarOutput[0].iBitmap = 0;
	m_tbiToolbarOutput[0].idCommand = ID_DIRECTORY_ITEM_REFRESH;
	m_tbiToolbarOutput[0].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
	m_tbiToolbarOutput[0].fsStyle = TBSTYLE_BUTTON;

	m_tbiToolbarOutput[1].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
	m_tbiToolbarOutput[1].fsStyle = TBSTYLE_SEP;

	m_tbiToolbarOutput[2].iBitmap = 1;
	m_tbiToolbarOutput[2].idCommand = ID_DIRECTORY_ITEM_COPY;
	m_tbiToolbarOutput[2].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
	m_tbiToolbarOutput[2].fsStyle = TBSTYLE_BUTTON;

	m_tbiToolbarOutput[3].iBitmap = 2;
	m_tbiToolbarOutput[3].idCommand = ID_DIRECTORY_ITEM_MOVE;
	m_tbiToolbarOutput[3].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
	m_tbiToolbarOutput[3].fsStyle = TBSTYLE_BUTTON;

	m_tbiToolbarOutput[4].iBitmap = 3;
	m_tbiToolbarOutput[4].idCommand = ID_DIRECTORY_ITEM_DELETE;
	m_tbiToolbarOutput[4].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
	m_tbiToolbarOutput[4].fsStyle = TBSTYLE_BUTTON;

	m_tbiToolbarOutput[5].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
	m_tbiToolbarOutput[5].fsStyle = TBSTYLE_SEP;

	m_tbiWinButtons[0].iBitmap = 1;
	m_tbiWinButtons[0].idCommand = ID_OUTPUT_WINDOW_HIDE;
	m_tbiWinButtons[0].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
	m_tbiWinButtons[0].fsStyle = TBSTYLE_BUTTON;
}

COutputWindow::~COutputWindow()
{
	m_imgToolbarOutput.Detach();
	m_imgWinButtons.Detach();
}


BEGIN_MESSAGE_MAP(COutputWindow, CSizingControlBar)
	//{{AFX_MSG_MAP(COutputWindow)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_LBN_DBLCLK(IDC_OUTPUT, OnDblclkOutput)
	ON_WM_CONTEXTMENU()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// COutputWindow message handlers

int COutputWindow::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	CRect rect(0, 0, 1, 1); DWORD dwStyle;
	if (CSizingControlBar::OnCreate(lpCreateStruct) == -1) return -1;

	dwStyle = WS_VISIBLE | WS_CHILD; CString szText( (LPCTSTR)IDS_CTRL_OUTPUT_WINDOW );
	m_stcCaptionOutput.Create(szText, dwStyle, rect, this, IDC_OUTPUT_CAPTION);

	dwStyle = WS_VISIBLE | WS_CHILD | CCS_NORESIZE | CCS_NODIVIDER | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS;
	m_btnWinButtons.Create(dwStyle, rect, this, IDC_OUTPUT_TOOLBAR);

	dwStyle = WS_VISIBLE | WS_CHILD | WS_VSCROLL | WS_HSCROLL | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | LBS_USETABSTOPS;
	m_lstConsoleOutput.Create(dwStyle, rect, this, IDC_OUTPUT_LIST);
	m_lstConsoleOutput.ModifyStyleEx(0, WS_EX_CLIENTEDGE, 0);

	m_lstConsoleOutput.SetHorizontalExtent(2560);
	m_lstConsoleOutput.SetTabStops(32); // dialog based unit (approximately 4 character)

	dwStyle = WS_VISIBLE | WS_CHILD;
	m_edtConsoleInput.Create(dwStyle, rect, this, IDC_OUTPUT_EDIT);
	m_edtConsoleInput.ModifyStyleEx(0, WS_EX_CLIENTEDGE, 0);
	m_edtConsoleInput.SetReadOnly(TRUE);

	// set image list
//	m_imgToolbarOutput.Create(IDB_OUTPUT_TOOLBAR, 16, 0, RGB(255, 0, 255));
//	m_btnToolbarOutput.SetImageList( & m_imgToolbarOutput );

	m_imgWinButtons.Create(IDB_WIN_BUTTONS, 12, 0, RGB(255, 0, 255));
	m_btnWinButtons.SetImageList( & m_imgWinButtons );

	// set control font
	CFont * pFont = CFont::FromHandle((HFONT)::GetStockObject(DEFAULT_GUI_FONT));
	LOGFONT lf; pFont->GetLogFont( & lf ); m_fontControl.CreateFontIndirect( & lf );
	m_stcCaptionOutput.SetFont( & m_fontControl, FALSE );

	// set output font
	ApplyOutputFont( FALSE );

	// initialize toolbar
//	m_btnToolbarOutput.AddButtons( 6, m_tbiToolbarOutput );
	m_btnWinButtons.AddButtons( 1, m_tbiWinButtons );
	
	// set occupied flag
	m_bOccupied = FALSE;

	return 0;
}

void COutputWindow::OnSize(UINT nType, int cx, int cy) 
{
	CSizingControlBar::OnSize(nType, cx, cy);

	INT nBegX = 2, nEndX = cx - 4;

//	nBegX  =  2; m_btnToolbarOutput.MoveWindow(nBegX, 2, 22, 106);
	nBegX +=  0; m_stcCaptionOutput.MoveWindow(nBegX, 24, 18, cy-26);
	nBegX +=  2; m_btnWinButtons.MoveWindow(nBegX, 4, 19, 18);
	nBegX += 20; m_lstConsoleOutput.MoveWindow(nBegX, 2, nEndX-nBegX, cy-24);
	nBegX +=  0; m_edtConsoleInput.MoveWindow(nBegX, cy-22, nEndX-nBegX, 20);
}

void COutputWindow::OnDblclkOutput() 
{
	INT nSelect = m_lstConsoleOutput.GetCurSel(); 
	if( nSelect == LB_ERR ) return;

	CString szString; m_lstConsoleOutput.GetText(nSelect, szString);
	if( ! szString.GetLength() ) return;

	INT nIndex1 = szString.Find('('); if( nIndex1 < 0 ) return;
	INT nIndex2 = szString.Find(')'); if( nIndex2 < 0 ) return;
	if( nIndex2 < nIndex1 ) return;

	CString szPathName = szString.Left(nIndex1);
	if( ! VerifyFilePath(szPathName) ) return;

	CString szLineNum  = szString.Mid(nIndex1+1, nIndex2-nIndex1-1);
	INT nLineNum = atoi(szLineNum); if( ! nLineNum ) return;

	CCedtApp * pApp = (CCedtApp *)AfxGetApp(); if( ! pApp ) return;
	pApp->PostOpenDocumentFile( szPathName, nLineNum );
}

void COutputWindow::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	CMenu * pMenu, context; context.LoadMenu(IDR_OUTPUT_WINDOW);
	pMenu = context.GetSubMenu(0);

	UINT nFlags = TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON;
	pMenu->TrackPopupMenu(nFlags, point.x, point.y, AfxGetMainWnd());
}

/////////////////////////////////////////////////////////////
// Operations
void COutputWindow::ApplyOutputFont(BOOL bRedraw)
{
	if( m_fontOutput.m_hObject ) m_fontOutput.DeleteObject();
	LOGFONT lf; memcpy( & lf, & CCedtView::m_lfMiscel[0x01], sizeof(LOGFONT) );

	CDC * pDC = m_lstConsoleOutput.GetDC();
	lf.lfHeight = -MulDiv( lf.lfHeight, pDC->GetDeviceCaps(LOGPIXELSY), 720 );
	m_lstConsoleOutput.ReleaseDC( pDC );
	m_fontOutput.CreateFontIndirect( & lf );

	m_lstConsoleOutput.SetFont( & m_fontOutput, bRedraw );
	m_edtConsoleInput.SetFont( & m_fontOutput, bRedraw );
}

void COutputWindow::EnableInputConsole(BOOL bEnable)
{
	m_edtConsoleInput.SetWindowText("");
	m_edtConsoleInput.SetReadOnly(!bEnable);
}

void COutputWindow::CopyAllTheContents()
{
	CMemText Block; TCHAR szText[2048];
	INT nCount = m_lstConsoleOutput.GetCount();
	for(INT i = 0; i < nCount; i++) {
		m_lstConsoleOutput.GetText(i, szText);
		Block.AddTail( szText );
	}
	CCedtView::SetClipboardData( Block );
}

void COutputWindow::ClearAllTheContents()
{
	m_lstConsoleOutput.ResetContent();
}

BOOL COutputWindow::AddStringToTheLast(LPCTSTR lpszString)
{
	if( m_lstConsoleOutput.GetCount() >= OUTPUT_MAX_LINE_COUNT ) {
		m_lstConsoleOutput.SetRedraw(FALSE);
		m_lstConsoleOutput.DeleteString(0);
		m_lstConsoleOutput.SetRedraw(TRUE);
	}

	INT nIndex = m_lstConsoleOutput.AddString(lpszString);
	if( nIndex == LB_ERR || nIndex == LB_ERRSPACE ) return FALSE;

	CRect rectClient; m_lstConsoleOutput.GetClientRect( & rectClient );
	CRect rectItem; m_lstConsoleOutput.GetItemRect(nIndex, & rectItem);

	INT nLineCount = rectClient.Height() / rectItem.Height();
	INT nTop = m_lstConsoleOutput.GetTopIndex();
	if( nIndex - nTop + 1 > nLineCount ) m_lstConsoleOutput.SetTopIndex( nIndex - nLineCount + 1);

	return TRUE;
}

BOOL COutputWindow::ReplaceTheLastString(LPCTSTR lpszString)
{
	INT nCount = m_lstConsoleOutput.GetCount();
	if( nCount > 0 ) m_lstConsoleOutput.DeleteString(nCount-1);

	INT nIndex = m_lstConsoleOutput.AddString(lpszString);
	if( nIndex == LB_ERR || nIndex == LB_ERRSPACE ) return FALSE;

	CRect rectClient; m_lstConsoleOutput.GetClientRect( & rectClient );
	CRect rectItem; m_lstConsoleOutput.GetItemRect(nIndex, & rectItem);

	INT nLineCount = rectClient.Height() / rectItem.Height();
	INT nTop = m_lstConsoleOutput.GetTopIndex();
	if( nIndex - nTop + 1 > nLineCount ) m_lstConsoleOutput.SetTopIndex( nIndex - nLineCount + 1);

	return TRUE;
}

BOOL COutputWindow::GetTheLastString(CString & szString)
{
	INT nCount = m_lstConsoleOutput.GetCount();
	if( nCount > 0 ) m_lstConsoleOutput.GetText(nCount-1, szString);
	else szString = "";

	return TRUE;
}

BOOL COutputWindow::PreTranslateMessage(MSG* pMsg) 
{
	switch( pMsg->message ) {
	case WM_KEYDOWN:
		switch( pMsg->wParam ) {
		case VK_RETURN:
			OnKeyReturn(); 
			return TRUE;
		case VK_ESCAPE:
			OnKeyEscape();
			return TRUE;
		}
		break;
	}

	if( pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP ) {
		TranslateMessage( pMsg );
		DispatchMessage( pMsg );
		return TRUE;
	} else return CSizingControlBar::PreTranslateMessage(pMsg);
}

void COutputWindow::OnKeyReturn()
{
	if( m_edtConsoleInput.GetStyle() & ES_READONLY ) return;
//	PostMessage( WM_COMMAND, ID_COMMAND_SEND_INPUT, 0L );

	TCHAR szInputString[4096];
	m_edtConsoleInput.GetLine(0, szInputString, 4096);

	CCedtView::SetChildInputString( szInputString );
	m_edtConsoleInput.SetWindowText(""); // clear input console
}

void COutputWindow::OnKeyEscape()
{
	if( m_edtConsoleInput.GetStyle() & ES_READONLY ) return;
//	PostMessage( WM_COMMAND, ID_COMMAND_KILL_PROCESS, 0L );

	CCedtView::KillChildProcess();
}

⌨️ 快捷键说明

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