edit.cpp

来自「BREW 应用」· C++ 代码 · 共 107 行

CPP
107
字号
// EDIT.cpp: implementation of the CEDIT class.
//
//////////////////////////////////////////////////////////////////////

#include "EDIT.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CEDIT::CEDIT(CAppMainHandler *pAppMain)
{
	AEEDeviceInfo di;
	m_pAppMain = pAppMain;

	ISHELL_GetDeviceInfo(m_pAppMain->m_pIShell, &di);
	m_Mi.m_nx = m_Mi.m_ny = 0;
	m_Mi.m_nWidth = di.cxScreen;
	m_Mi.m_nHeight = di.cyScreen;

	AEEFont font;
	int pnAscent, pnDescent;
	int m_nFontHeight = IDISPLAY_GetFontMetrics (m_pAppMain->m_pIDisplay, font, &pnAscent, &pnDescent);
	m_Mi.m_nLineCount = m_Mi.m_nHeight / (m_nFontHeight + 4);
	
	for( int i=0; i< m_Mi.m_nLineCount; i++ )
		m_Mti.m_pLineText[i] = (char*)new char[30];
	m_Mti.m_nStartLine = 0;
	m_Mti.m_pMemoText = NULL;
	m_ptagFile = NULL;
}

CEDIT::~CEDIT()
{

}

void CEDIT::Size(int x, int y, int width, int height)
{
	m_Mi.m_nx = x;
	m_Mi.m_ny = y;
	m_Mi.m_nWidth = width;
	m_Mi.m_nHeight = height;

	m_Mi.m_nLineCount = m_Mi.m_nHeight / (m_nFontHeight + 4);
}

int CEDIT::Write(char *pText, int nSize)
{
	m_ptagFile->Write(pText, nSize);
	m_ptagFile->Write((char*)20, 1);
	return nSize + 1;
}

void CEDIT::SetText(char *pText)
{
	if( m_ptagFile )	
		delete m_ptagFile;
	m_ptagFile = new CTAGTEXTFILE(m_pAppMain, m_Mi.m_nWidth);
	m_ptagFile->Open("cocozaTXT");
	MakeTagText(pText, 0);
}

void CEDIT::MakeTagText(char *pText, int nSize)
{
	char chBuf[3];
	int nOneSize, nTotalSize, nTextCount;
	int nCount, nTemp;
	char *pStartPos;
	AEEFont font;
	
	nOneSize = nTotalSize = nTextCount = 0;
	pStartPos = pText;
	while( pText != NULL ) {
		if( *pText & 0x80 ) {
			MEMCPY(chBuf, pText, 2);
			nCount = 2;
		}
		else {
			MEMCPY(chBuf, pText, 1);
			if ( chBuf[0] == '\r' ) {				
				Write(pStartPos, nTextCount);
				nTextCount = nTotalSize = 0;
				pStartPos = pText + 1;
				continue;
			}
				break;
			if ( chBuf[0] == '\n' ) 
				*pText = ' ';
			nCount = 1;
		}
		chBuf[nCount] = '\0';
		nOneSize = IDISPLAY_MeasureTextEx(m_pAppMain->m_pIDisplay, font, (AECHAR*)chBuf, 1, -1, &nTemp);
		nTotalSize += nOneSize;
		if( m_Mi.m_nWidth > nTotalSize )
			nTextCount += nCount;
		else {			
			Write(pStartPos, nTextCount);
			nTextCount = nTotalSize = 0;
			pStartPos = pText+1;
			continue;
		}
		pText += nCount;
	}
	Write(pStartPos, nTextCount);
}

⌨️ 快捷键说明

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